ادارہ پاکستان براےء آزاد مصدر

Pakistan Open Source Organization


MARC / PERL: Koha Integrated Library System

MARC Tutorial

Debugging with as_formatted()

Since raw USMARC data isn't very easy for humans to read, it is often useful to be able to see thecontents of your MARC::Record object represented in a 'pretty' way for debugging purposes. If youhave a MARC::Record object you'd like to pretty-print, use the as_formatted()method.

1 ## Example W2
2
3 ## create a MARC::Record object.
4 use MARC::Record;
5 my $record = MARC::Record->new();
6
7 $record->leader('00903pam 2200265 a 4500');
8
9 $record->append_fields(
10 MARC::Field->new('100','1','', a=>'Logan, Robert K.', d=>'1939-'),
11 MARC::Field->new('245','1','4', a=>'The alphabet effect /', c=>'Robert K. Logan.')
12 );
13
14 ## pretty print the record.
15 print $record->as_formatted(), "\n";

This code will pretty print the contents of the newly created record:

LDR 00903pam 2200265 a 4500\
100 1 _aLogan, Robert K.
 _d1939-
245 14 _aThe alphabet effect /
 _cRobert K. Logan.

Notice on lines 9-12 how you can add a list of new fields by creating MARC::Field objects within a callto append_fields(). This is yet another shorthand method to those shown in recipes C1 and W1.For more pretty-printing capabilities, try marcdump()in our next recipe.

Debugging with marcdump()

If you have written USMARC data to a file (as in recipe W2) and you would like to verify that the data is stored correctly you can use the marcdump command line utility that was installed with the MARC::Record package:

% marcdump record.dat
record.dat
LDR 00122pam 2200049 a 4500
100 1_aLogan, Robert K.
  _d1939-
245 14 _aThe alphabet effect /
 _cRobert K. Logan.
 
Recs Errs Filename
----- ----- --------
10 record.dat

As you can see, this command results in the record being pretty printed to your screen (STDOUT) similarly to the as_formatted method from recipe W2. It is useful for verifying your USMARC data after it has been stored on disk. More details about debugging are found later in VALIDATING.


UPDATING

Now that you know how to read, write and create MARC data, you have the tools you need to update or edit exiting MARC data. Updating MARC data is a common task for library catalogers. Sometimes there are huge amounts of records that need to be touched up... and while the touch ups are very detail oriented, they are also highly repetitive. Luckily, computers are tireless, and not very prone to error (assuming the programmer isn't). When libraries receive large batches of MARC records for electronic text collections such as NetLibrary, Making of America, or microfiche sets like Early American Imprints, the records are often loaded into an online system and then the system is used to update the records. Unfortunately, not all these systems are created equal, and catalogers have to spend a great deal of time touching up each individual record. An alternative would be to process the records prior to import and then, once in the system, the records would not need editing. This scenario would save a great deal of time for the cataloger who would be liberated to spend their time doing original cataloging... which computers are notably bad at!