| 1 | #!/usr/bin/perl |
| 2 | use MARC::Batch; |
| 3 | use strict; |
| 4 | use warnings; |
| 5 | use Encode qw(:fallback_all); |
| 6 | |
| 7 | my $batch = MARC::Batch->new( 'USMARC', @ARGV ); |
| 8 | my $oldencoding = $PerlIO::encoding::fallback; |
| 9 | $batch->strict_off(); |
| 10 | $batch->warnings_off(); |
| 11 | |
| 12 | my ($count_raw, $count_attempted, $count_901c) = (0, 0, 0); |
| 13 | eval { |
| 14 | while ( my $marc = $batch->next ) { |
| 15 | $PerlIO::encoding::fallback = Encode::WARN_ON_ERR | Encode::PERLQQ; |
| 16 | $count_attempted++; |
| 17 | eval { |
| 18 | my $field_901c = $marc->subfield(901,"c"); |
| 19 | if(defined $field_901c) { |
| 20 | chomp $field_901c; |
| 21 | $count_901c++ if ($field_901c =~ /^.+$/); |
| 22 | printf "%s\n",$field_901c; |
| 23 | } |
| 24 | $count_raw++; |
| 25 | }; |
| 26 | warn "Inner: $@" if $@; |
| 27 | } |
| 28 | }; |
| 29 | warn "Outer: $@" if $@; |
| 30 | |
| 31 | $PerlIO::encoding::fallback = $oldencoding; |
| 32 | printf STDERR "Count (attempted): %d\n",$count_attempted; |
| 33 | printf STDERR "Count (raw): %d\n",$count_raw; |
| 34 | printf STDERR "Count (901c): %d\n",$count_901c; |