use MARC::Batch;
use strict;
use warnings;
-
+use Encode qw(:fallback_all);
my $batch = MARC::Batch->new( 'USMARC', @ARGV );
+my $oldencoding = $PerlIO::encoding::fallback;
$batch->strict_off();
$batch->warnings_off();
-while ( my $marc = $batch->next ) {
- print $marc->subfield(901,"c"), "\n";
-}
+my ($count_raw, $count_attempted, $count_901c) = (0, 0, 0);
+eval {
+ while ( my $marc = $batch->next ) {
+ $PerlIO::encoding::fallback = Encode::WARN_ON_ERR | Encode::PERLQQ;
+ $count_attempted++;
+ eval {
+ my $field_901c = $marc->subfield(901,"c");
+ if(defined $field_901c) {
+ chomp $field_901c;
+ $count_901c++ if ($field_901c =~ /^.+$/);
+ printf "%s\n",$field_901c;
+ }
+ $count_raw++;
+ };
+ warn "Inner: $@" if $@;
+ }
+};
+warn "Outer: $@" if $@;
+
+$PerlIO::encoding::fallback = $oldencoding;
+printf STDERR "Count (attempted): %d\n",$count_attempted;
+printf STDERR "Count (raw): %d\n",$count_raw;
+printf STDERR "Count (901c): %d\n",$count_901c;