9 my $marcxml = shift || help();
11 open HOLDINGS, '>', "holdings";
12 open X, '>', "holdings.x";
13 open Z, '>', "holdings.z";
14 open ALL852, '>', "holdings.all852";
20 my %all852 = ( x => {}, z => {} ); # hash of all subfields in all 852s
22 my $t = XML::Twig->new( twig_handlers => { record => \&record } );
23 $t->parsefile($marcxml);
24 #print ALL852 to_json(\%all852);
25 print ALL852 Dump(%all852);
29 $holdings = { copies => [] };
31 my @dfields = $r->children('datafield');
32 for my $d (@dfields) {
33 process_datafields($d)
36 for my $copy (@{$holdings->{copies}})
37 { print_reports($copy) }
39 $count++; print "\r$count";
42 sub process_datafields {
45 if ($d->{'att'}->{'tag'} == 903) {
46 my $s = $d->first_child('subfield');
47 $holdings->{id} = $s->text;;
51 if ($d->{'att'}->{'tag'} == 852) {
52 push @{$holdings->{copies}}, { x =>[], z => [] };
53 $holdings->{copies}[-1]{copyid} = $copyid;
54 my @subs = $d->children('subfield');
63 my $copy = $holdings->{copies}[-1];
65 my $code = $s->{'att'}->{'code'};
68 if ($code eq 'x' or $code eq 'z') {
69 push @{$copy->{$code}}, $value;
70 my ($k,$v) = split /:/, $value;
71 $all852{$code}{$k} = $v;
73 $copy->{$code} = $value;
74 $all852{$code} = $value;
82 print X join("\t", $holdings->{id}, $copy->{copyid}, $note, $_), "\n";
87 print Z join("\t", $holdings->{id}, $copy->{copyid}, $note, $_), "\n";
90 print HOLDINGS join("\t", $holdings->{id}, $copy->{copyid},
91 $copy->{b}, $copy->{p}, $copy->{h}, $copy->{9}), "\n";
97 Usage is: extract_holdings MARCXML_FILE