Sort with MARC::Record

2005-01-31 Thread Jackie Shieh

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]


RE: Sort with MARC::Record

2005-01-31 Thread Bryan Baldus
Has anyone sorted a file of hundreds of records by 001?

I haven't done sorting yet, but you may want to see if my MARC::BBMARC's
[1], MARC::BBMARC::updated_record_hash()  sub may be of use. It reads a file
of MARC records and stores them in a hash with the 001 as key, the raw MARC
as value. It should be fairly simple, then, to use this to output the
desired records in the proper order. It should work ok on small files of
MARC records, but depending on your system's memory, may die a horrible
death on large record sets.

My extractbycontrolno script [2] reads a file of control numbers (using
BBMARC's updated_record_array() to save memory) and a separate file of MARC
records, and outputs the matching records. It doesn't do any sorting, so it
depends on the order it finds the records.

[1] MARC::BBMARC is available directly from my homepage at:
http://home.inwave.com/eija/bryanmodules/, 
or bundled with MARC::Errorchecks on CPAN
http://search.cpan.org/~eijabb/MARC-Errorchecks-1.06/
[2]
http://home.inwave.com/eija/fullrecscripts/Extraction/extractbycontrolno.txt

Hope this helps,

Bryan Baldus
[EMAIL PROTECTED]
[EMAIL PROTECTED]
http://home.inwave.com/eija
 



Re: Sort with MARC::Record

2005-01-31 Thread Leif Andersson

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]