/[webpac2]/trunk/bin/dump2marc.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/bin/dump2marc.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1316 - (hide annotations)
Fri Nov 6 22:30:52 2009 UTC (14 years, 6 months ago) by dpavlin
Original Path: branches/Sack/bin/dump2marc.pl
File MIME type: text/plain
File size: 979 byte(s)
convert marcdump output back to marc file

1 dpavlin 1316 #!/usr/bin/perl
2    
3     # Convert marcdump output back to marc file
4    
5     use warnings;
6     use strict;
7    
8     use MARC::Record;
9     use Data::Dump qw(dump);
10     use Encode;
11    
12     my @fields;
13    
14     sub parse_subfields {
15     my $text = shift;
16     if ( $text =~ /^_([a-z])(.+)$/ ) {
17     return ( $1, $2 );
18     } else {
19     $text =~ s/^ // || warn "no space in front of: '$text'\n";
20     return $text;
21     }
22     }
23    
24     my $leader;
25    
26     while(<>) {
27     chomp;
28     $_ = decode('utf-8', $_);
29    
30     if ( /^LDR (.+)$/ ) {
31     $leader = $1;
32     } elsif ( /^(\d\d\d) (.)(.) (.+)$/ ) {
33     if ( $1 < 10 ) {
34     push @fields, [ $1, parse_subfields($4) ];
35     } else {
36     push @fields, [ $1, $2, $3, parse_subfields($4) ];
37     }
38     } elsif ( /^\s{7}_([a-z])(.+)$/ ) {
39     push @{ $fields[ $#fields ] }, $1, $2;
40     } elsif ( /^$/ ) {
41     warn dump( @fields );
42    
43     my $marc = new MARC::Record;
44     $marc->encoding( 'utf-8' );
45     $marc->leader( $leader );
46     $marc->add_fields( @fields );
47    
48     warn $marc->as_formatted;
49     print $marc->as_usmarc;
50    
51     @fields = ();
52     } else {
53     warn "IGNORED: $_\n";
54     }
55    
56     }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26