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