9 my $marcxml = shift || help();
11 open HOLDINGS, '>', "holdings";
12 open X, '>', "holdings.x";
13 open Z, '>', "holdings.z";
14 open ALL852, '>', "holdings.all852";
18 my %all852 = ( x => {}, z => {} ); # hash of all subfields in all 852s
20 my $t = XML::Twig->new( twig_handlers => { record => \&record } );
21 $t->parsefile($marcxml);
22 #print ALL852 to_json(\%all852);
23 print ALL852 Dump(%all852);
27 $holdings = { copies => [] };
29 my @dfields = $r->children('datafield');
30 for my $d (@dfields) {
31 process_datafields($d)
34 for my $copy (@{$holdings->{copies}})
35 { print_reports($copy) }
39 sub process_datafields {
42 if ($d->{'att'}->{'tag'} == 903) {
43 my $s = $d->first_child('subfield');
44 $holdings->{id} = $s->text;;
48 if ($d->{'att'}->{'tag'} == 852) {
49 push @{$holdings->{copies}}, { x =>[], z => [] };
50 $holdings->{copies}[-1]{copyid} = $copyid;
51 my @subs = $d->children('subfield');
60 my $copy = $holdings->{copies}[-1];
62 my $code = $s->{'att'}->{'code'};
65 if ($code eq 'x' or $code eq 'z') {
66 push @{$copy->{$code}}, $value;
67 my ($k,$v) = split /:/, $value;
68 $all852{$code}{$k} = $v;
70 $copy->{$code} = $value;
71 $all852{$code} = $value;
79 print X join("\t", $holdings->{id}, $copy->{copyid}, $note, $_), "\n";
84 print Z join("\t", $holdings->{id}, $copy->{copyid}, $note, $_), "\n";
87 print HOLDINGS join("\t", $holdings->{id}, $copy->{copyid},
88 $copy->{b}, $copy->{p}, $copy->{h}, $copy->{9}), "\n";
94 Usage is: extract_holdings MARCXML_FILE