/[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

Contents of /trunk/bin/dump2marc.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1322 - (show annotations)
Tue Jan 26 14:16:36 2010 UTC (14 years, 3 months ago) by dpavlin
File MIME type: text/plain
File size: 1022 byte(s)
Merge remote branch 'remotes/Sack'

Conflicts:
	bin/dump2marc.pl
1 #!/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 $debug = 0;
13 my @fields;
14
15 sub parse_subfields {
16 my $text = shift;
17 if ( $text =~ /^_([a-z])(.+)$/ ) {
18 return ( $1, $2 );
19 } else {
20 $text =~ s/^ // || warn "no space in front of: '$text'\n";
21 return $text;
22 }
23 }
24
25 my $leader;
26
27 while(<>) {
28 chomp;
29 $_ = decode('utf-8', $_);
30
31 if ( /^LDR (.+)$/ ) {
32 $leader = $1;
33 } elsif ( /^(\d\d\d) (.)(.) (.+)$/ ) {
34 if ( $1 < 10 ) {
35 push @fields, [ $1, parse_subfields($4) ];
36 } else {
37 push @fields, [ $1, $2, $3, parse_subfields($4) ];
38 }
39 } elsif ( /^\s{7}_([a-z])(.+)$/ ) {
40 push @{ $fields[ $#fields ] }, $1, $2;
41 } elsif ( /^$/ ) {
42 warn dump( @fields ) if $debug;
43
44 my $marc = new MARC::Record;
45 $marc->encoding( 'utf-8' );
46 $marc->leader( $leader );
47 $marc->add_fields( @fields );
48
49 warn $marc->as_formatted, $/, $/;
50 print $marc->as_usmarc;
51
52 @fields = ();
53 } else {
54 warn "IGNORED: $_\n" if $debug;
55 }
56
57 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26