Thanks for all the responses.  They are really helpful, especially the example 
Arvin gave.  That's exactly what I was looking for.

Thanks again!

Bin

-----Original Message-----
From: arvinport...@lycos.com [mailto:arvinport...@lycos.com] 
Sent: Friday, October 14, 2011 7:49 AM
To: Zhang, Bin
Cc: perl4lib@perl.org
Subject: Re: MARC::Batch question

As I deal with this all the time I've started including code to spit out these 
records into their own file. That has been very useful:

my $batch = MARC::Batch->new('USMARC', '../full_export.out'); 
$batch->strict_off(); $batch->warnings_off();

my ($record, $counter, @rejected_record_counter); eval { $record = 
$batch->next; }; while ($record) {
   $counter++;
   if ($@) {
      print STDERR "Runtime error record $counter: $@\n";
      push @rejected_record_counter, $counter;
      eval { $record = $batch->next; };
      next;
   }

   # Continue to process valid records ...

      eval { $record = $batch->next; };
}

# Processing complete.
# Now split the input file into records and loop through to spit out the bad 
ones

if (@rejected_record_counter) {
   open (REJECTS, ">badrecs.marc") or die "Couldn't open badrecs.marc for 
writing: $!\n";
   local $/ = "\x1E\x1D";
   open (INFILE, '../full_export.out') or die "Couldn't open ../full_export.out 
for reading: $!\n";
   my $record_counter;
   while (my $record = <INFILE>) {
      $record_counter++;
      if ($record_counter == $rejected_record_counter[0]) {
         print REJECTS $record;
         shift @rejected_record_counter;
         last unless @rejected_record_counter;
      }
   }
   close (INFILE);
   close (REJECTS);
}


Arvin

On Oct 13, 2011, Zhang, Bin <bzh...@csus.edu> wrote: 

Hi,

I have to admit my Perl skill is very limited, so this may be a dumb question, 
but I can't seem to find answer.   When I use MARC::Batch to read records from 
our catalog (III) export file, I can't seem to find a way to skip an error 
record.   When I ran the following against an III export MARC file, it stopped 
at a record with error.

utf8 "\xBC" does not map to Unicode at /usr/lib/perl/5.10/Encode.pm line 174.

Ideally I would like to be able to log the error and move to the next record.

Any help you can offer is greatly appreciated!


--script--
my $batch = MARC::Batch->new('USMARC', '../full_export.out'); 
$batch->strict_off(); $batch->warnings_off();

my $linter = MARC::Lint->new();
my $counter = 0;

while(my $record = $batch->next() ) {
    $counter++;
    if($counter != 22507) {
        $linter->check_record($record);
        my @warnings = $linter->warnings();
        if(@warnings) {
            print "RECORD $counter\n";
            print join("\n", @warnings), "\n";
        }
    }
}


---
Bin Zhang
Digital Information Services Librarian
Library 3501D
Library Systems & IT Services, University Library California State University, 
Sacramento
2000 State University Drive East, Sacramento, CA 95819-6039
(916) 278-5664 (O); (916) 278-3891 (F)
bzhang AT csus DOT edu


Reply via email to