From: Dobrica Pavlinusic Date: Fri, 7 Jul 2006 21:11:01 +0000 (+0000) Subject: support for repeatable subfields, version bump to 0.20 X-Git-Url: http://git.rot13.org/?p=Biblio-Isis;a=commitdiff_plain;h=b038a505104c4212dddfa71ab5914b49c3c8e4e7;hp=a6f0185ff3c26ea02a5903cde0e22c1878e7f9fb support for repeatable subfields, version bump to 0.20 THIS MIGHT BE INCOMPATIBILE CHANGE for old programs if they always expect to get scalar for values in hash generated by to_hash. git-svn-id: file:///home/dpavlin/svn/Biblio-Isis/trunk@50 4670fa4d-42ec-0310-ab5b-a66af6943492 --- diff --git a/lib/Biblio/Isis.pm b/lib/Biblio/Isis.pm index da1fcd7..76f20ba 100644 --- a/lib/Biblio/Isis.pm +++ b/lib/Biblio/Isis.pm @@ -7,7 +7,7 @@ use File::Glob qw(:globally :nocase); BEGIN { use Exporter (); use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); - $VERSION = 0.14; + $VERSION = 0.20; @ISA = qw (Exporter); #Give a hoot don't pollute, do not export more than needed by default @EXPORT = qw (); @@ -464,6 +464,13 @@ which will be used for identifiers, C and C like this: } ], +In case there are repeatable subfields in record, this will create +following structure: + + '900' => [ { + 'a' => [ 'foo', 'bar', 'baz' ], + }] + This method will also create additional field C<000> with MFN. =cut @@ -496,7 +503,16 @@ sub to_hash { if ($l =~ m/\^/) { foreach my $t (split(/\^/,$l)) { next if (! $t); - $val->{substr($t,0,1)} = substr($t,1); + my ($sf,$v) = (substr($t,0,1), substr($t,1)); + warn "### $k^$sf:$v",$/ if ($self->{debug} > 1); + if (ref( $val->{$sf} ) eq 'ARRAY') { + push @{ $val->{$sf} }, $v; + } elsif (defined( $val->{$sf} )) { + # convert scalar field to array + $val->{$sf} = [ $val->{$sf}, $v ]; + } else { + $val->{$sf} = $v; + } } } else { $val = $l; diff --git a/scripts/dump_isisdb.pl b/scripts/dump_isisdb.pl index d923ba7..c2f5227 100755 --- a/scripts/dump_isisdb.pl +++ b/scripts/dump_isisdb.pl @@ -1,11 +1,20 @@ #!/usr/bin/perl -w use strict; -#use blib; +use blib; use Biblio::Isis; use Getopt::Std; -use Data::Dumper; + +BEGIN { + eval "use Data::Dump"; + + if (! $@) { + *Dumper = *Data::Dump::dump; + } else { + use Data::Dumper; + } +} my %opt; getopts('dn:', \%opt); @@ -14,7 +23,7 @@ my $isisdb = shift @ARGV || die "usage: $0 [-n number] [-d] /path/to/isis/BIBL\n my $isis = Biblio::Isis->new ( isisdb => $isisdb, - debug => $opt{'d'}, + debug => $opt{'d'} ? 2 : 0, include_deleted => 1, # read_fdt => 1, );