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

Pakistan Open Source Organization


MARC / PERL: Koha Integrated Library System

MARC Tutorial

Then create a separate program that uses your subclass to validate your MARC records. You'll need to make sure your program is able to find your module (in this case, MyLint.pm)... this can be achieved by putting both MyLint.pm and the following program in the same directory:

1 ## Example V3
2
3 use MARC::Batch;
4 use MyLint;
5
6 my $linter = MyLint->new();
7 my $batch = MARC::Batch->new('USMARC','file.marc');
8 my $counter = 0;
9
10 while (my $record = $batch->next()) {
11
12 $counter++;
13
14 ## check the record
15 $linter->check_record($record);
16
17 ## get the warnings, and print them out
18 my @warnings = $linter->warnings();
19 if (@warnings) {
20 print "RECORD $counter\n";
21 print join("\n",@warnings),"\n";
22 }
23
24 }

Notice how the call to check_record() at line 15 automatically calls the check_record in MARC::Lint. The property of inheritance is what makes this happen. $linter is an instance of the MyLint class, and MyLint inherits from the MARC::Lint class, which allows $linterto inherit all the functionality of a normal MARC::Lint object plus the new functionality found in the check_856 method. Notice also that we don't have to call check_856() directly. The call to check_record() automatically looks for any check_XXX methods that it can call to verify the record. Pretty neat stuff. If you've added validation checks that you think could be of use to the general public, please share them on the perl4lib mailing list, or become a developer and add them to the source!

SWOLLEN APPENDICES

Brian Eno fans might catch this reference to his autobiography which was comprised of a years worth of diary entries plus extra topics at the end, and was entitled "A Year With Swollen Appendices". The following section is a grab bag group of appendices. Many of them are not filled in yet; this is because they are just ideas... so perhaps the appendices aren't that swollen yet. Feel free to suggest new ones, or to fill these in.

Comparing Collections

Authority Records

URLs

ISBN/ISSNs

Call numbers

Subject headings

Suppose you have a batch of MARC records and you want to extract all the subject headings, generating a report of how many times each subject heading appeared in the batch:

1 use MARC::File::USMARC;
2 use constant MAX => 20;
3
4 my %counts;
5
6 my $filename = shift or die "Must specify filename\n";
7 my $file = MARC::File::USMARC->in( $filename );
8
9 while ( my $marc = $file->next() ) {
10 for my $field ( $marc->field("6..") ) {
11 my $heading = $field->subfield('a');
12
13 # trailing whitespace / punctuation.
14 $heading =~ s/[.,]?\s*$//;
15
16 # Now count it.
17 ++$counts{$heading};
18 }
19 }
20 $file->close();
21
22 # Sort the list of headings based on the count of each.
23 my @headings = reverse sort { $counts{$a} <=> $counts{$b} } keys %counts;
24
25 # Take the top N hits...
26 @headings = @headings[0..MAX-1];
27
28 # And print out the results.
29 for my $heading ( @headings ) {
30 printf( "%5d %s\n", $counts{$heading}, $heading );
31 }