better example with repetable field and subfields
[MARC-Fast] / scripts / dump_fastmarc.pl
index eb0fd0c..f9e96f2 100755 (executable)
@@ -1,11 +1,11 @@
 #!/usr/bin/perl -w
 
 use strict;
-use blib;
+use lib 'lib';
 
 use MARC::Fast;
 use Getopt::Std;
-use Data::Dumper;
+use Data::Dump qw/dump/;
 
 =head1 NAME
 
@@ -19,13 +19,13 @@ dump_fastmarc.pl - display MARC records
 
 =over 16
 
-=item -n number
+=item -o offset
 
-dump just record C<number>
+dump records starting with C<offset>
 
 =item -l limit
 
-import just first C<limit> records
+dump just C<limit> records
 
 =item -h
 
@@ -40,9 +40,9 @@ turn debugging output on
 =cut
 
 my %opt;
-getopts('dn:l:h', \%opt);
+getopts('do:l:h', \%opt);
 
-my $file = shift @ARGV || die "usage: $0 [-n number] [-l limit] [-h] [-d] file.marc\n";
+my $file = shift @ARGV || die "usage: $0 [-o offset] [-l limit] [-h] [-d] file.marc\n";
 
 my $marc = new MARC::Fast(
        marcdb => $file,
@@ -65,14 +65,9 @@ if (my $mfn = $opt{n}) {
 
 for my $mfn ($min .. $max) {
        my $rec = $marc->fetch($mfn) || next;
-       print "rec is ",Dumper($rec) if ($opt{d});
+       print "rec is ",dump($rec) if ($opt{d});
        print "REC $mfn\n";
-       foreach my $f (sort keys %{$rec}) {
-               my $dump = join('', @{ $rec->{$f} });
-               $dump =~ s/\x1e$//;
-               $dump =~ s/\x1f/\$/g;
-               print "$f\t$dump\n";
-       }
-       print "\n";
-       print "hash is ",Dumper($marc->to_hash($mfn)) if ($opt{h});
+       print $marc->last_leader,"\n";
+       print $marc->to_ascii($mfn),"\n";
+       print "hash is ",dump($marc->to_hash($mfn, include_subfields => 1)) if ($opt{h});
 }