Thank y'all, Bryan Baldus & Leif Andersson!

No worries... all records have been checked with the
presence of an 001.

--Jackie

On Mon, 31 Jan 2005, Leif Andersson wrote:

>
> This is one way to do it:
>
> #!/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) {
>     print $records[$rec->[0]];
> }
>
> __END__
>
> You may need to guard yourself against records having no field 001.
> 518 records, if that is what you have to deal with, should under "normal" 
> conditions not raise any memory issues.
>
> Leif
>
>
> -----Ursprungligt meddelande-----
> Från: Jackie Shieh [mailto:[EMAIL PROTECTED]
> Skickat: den 31 januari 2005 21:40
> Till: perl4lib@perl.org
> Ämne: Sort with MARC::Record
>
>
>
> Has anyone sorted a file of hundreds of records by 001?
>
> I have a file of 518 records unsorted and a file of
> sorted ids from 001 (406).  I would like to sort my marc
> 518 records first before extracting the 406 records based
> on the 2nd file from the set of 518 records.  I'd appreciate
> any suggestions, thanks.
>
> --Jackie
>
> |Jackie Shieh
> |Special Projects & Collections Team
> |Harlan Hatcher Graduate Library
> |University of Michigan
> |920 North University
> |Ann Arbor, MI        48109-1205
> |Phone: 734.936.2401   FAX: 734.615.9788
> |E-mail: [EMAIL PROTECTED]
>
>
>
>
>

Reply via email to