utf8 pragma
[migration-tools.git] / split_marc.pl
1 #!/usr/bin/perl
2 use open ':utf8';
3 use MARC::Batch;
4 use MARC::Record;
5 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
6 use MARC::Field;
7 use POSIX;
8
9 my $split_every = $ARGV[0];
10 my $count = 0;
11
12 binmode(STDOUT, ':utf8');
13 binmode(STDIN, ':utf8');
14
15 foreach $argnum ( 1 .. $#ARGV ) {
16
17         print STDERR "Processing " . $ARGV[$argnum] . "\n";
18
19         my $batch = MARC::Batch->new('XML',$ARGV[$argnum]);
20         $batch->strict_off();
21         $batch->warnings_off();
22
23         while ( my $record = $batch->next() ) {
24
25         $count++;
26
27                 my $filename = $ARGV[$argnum] . ".split." .  floor( $count / $split_every ) . ".xml";
28
29                 open FILE, ">>$filename";
30                 binmode(FILE, ':utf8');
31                 print FILE $record->as_xml();
32                 close FILE;
33         }
34     print STDERR "Processed $count records.\n";
35 }
36