hi
i have inherited this piece of code and i have been wondering hard about how i can
print the different @records returned from the subroutine? im not even sure whats on
my hand here. is this a hash of arrays or a hash of array references? and how do i
unwind those?
martin, beginning perl.
my @records = &parse_pubmed_fcgi( [ qw(UI AU TI TA VI IP PG DA) ] );
###################### subroutines ####################
sub parse_pubmed_fcgi {
my ( $keys ) = @_;
my ( @records, $record, $record_id, $line, $key );
my %wants = map { $_ => 1 } @{ $keys };
while ( defined ($line = <>) ) {
chop $line;
if ( $line =~ /^(UI)\s*-/ ) {
$key = $1;
if ( $record ) {
push @records, $record;
undef $record;
}
}
if ( $line =~ /^([A-Z]+)\s*-\s*(.+)/ ) {
$key = $1;
push @{ $record->{ $key } }, $2 if $wants{ $key };
}
elsif ( $line =~ /^\s+(\S.*)/ ) {
$record->{ $key }->[-1] .= " $1" if $wants{ $key };
}
}
push @records, $record if $record;
if ( wantarray ) {
return @records;
} else {
return \@records;
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]