9 my $marcxml = shift || help();
10 my $htag = shift || help();
12 open HOLDINGS, '>', "holdings";
13 open X, '>', "holdings.x";
14 open Z, '>', "holdings.z";
16 my %all852 = ( x => {}, z => {} ); # hash of all subfields in all 852s
22 my $total = `grep -c '<record' $marcxml`;
26 my $yaml = YAML::Tiny->new;
27 my $t = XML::Twig->new( twig_handlers => { record => \&record } );
28 $t->parsefile($marcxml);
29 $yaml->[0] = \%all852;
30 $yaml->write('holdings.sample');
35 $holdings = { copies => [] };
37 my @dfields = $r->children('datafield');
39 { process_datafields($d) }
41 for my $copy (@{$holdings->{copies}})
42 { print_reports($copy) }
46 $percent = int(($count / $total) * 100);
47 print "\r$percent% done ($count)" if ($percent != $prevper);
51 sub process_datafields {
54 if ($d->{'att'}->{'tag'} == 903) {
55 my $s = $d->first_child('subfield');
56 $holdings->{id} = $s->text;;
60 if ($d->{'att'}->{'tag'} == $htag) {
61 push @{$holdings->{copies}}, { x =>[], z => [] };
62 $holdings->{copies}[-1]{copyid} = $copyid;
63 my @subs = $d->children('subfield');
72 my $copy = $holdings->{copies}[-1];
74 my $code = $s->{'att'}->{'code'};
77 if ($code eq 'x' or $code eq 'z') {
78 push @{$copy->{$code}}, $value;
79 my ($k,$v) = split /:/, $value;
80 $all852{$code}{$k} = $v;
82 $copy->{$code} = $value;
83 $all852{$code} = $value;
88 return unless defined $holdings->{id};
92 print X join("\t", $holdings->{id}, $copy->{copyid}, $note, $_), "\n";
97 print Z join("\t", $holdings->{id}, $copy->{copyid}, $note, $_), "\n";
100 for (qw( copyid b p h 9 ))
101 { $copy->{$_} = '' unless defined $copy->{$_} }
102 print HOLDINGS join("\t", $holdings->{id}, $copy->{copyid},
103 $copy->{b}, $copy->{p}, $copy->{h}, $copy->{9}), "\n";
109 Usage is: extract_holdings MARCXML_FILE HOLDINGS_TAG