I am sorry, my earlier posting contained a little error. The last print statement should read
print $records[$rec->[0]]->as_usmarc(); Jackie also pointed out that his 001 is alphanumeric. So he changed the comparision operator from "<=>" (numeric) to "cmp" The script should have looked like this: #!/usr/local/bin/perl -w use strict; use MARC::Batch; # sort marc records on field 001 # usage: sort_marc.pl infil.mrc > utfil.mrc my $batch = new MARC::Batch( 'USMARC', $ARGV[0] ); my @records = (); my @f001 = (); my $idx = 0; while ( my $MARC = $batch->next ) { push(@records, $MARC); push(@f001, [$idx++, $MARC->field("001")->as_string]); } foreach my $rec (sort { $a->[1] <=> $b->[1] } @f001) { # for alphanumeric comparision use: foreach my $rec (sort { $a->[1] cmp $b->[1] } @f001) { print $records[$rec->[0]]->as_usmarc(); } __END__ Leif