[pm-h] hash creation - syntax error
Robert Boone
robo4288 at gmail.com
Sat May 10 14:30:54 PDT 2008
The problem is you can't declare a hash and assign it like that. You
would need to assign it a list when you declare it. Plus by using "my"
to declare the hashes you would lose the data at the end of each loop.
Here is one way to solve your problem.
use Data::Dumper;
my $snnc = "";
my @fields = ();
my %name = ();
my %formalname = ();
my %chapters = ();
# open(my $fh, '<', 'sequence-name-name-chapters' )
# or die "unable to open 'sequence-name-name-chapters': $!";
chomp( my @snnc = <DATA> );
foreach $snnc (@snnc) {
@fields = split / +\+/, $snnc;
print $fields[0], "\n"; # sequence number of the book
print $fields[1], "\n"; # short name of the book
print $fields[2], "\n"; # formal name of the book
print $fields[3], "\n"; # number of chapters in the book
print "\n";
$name{$fields[0]} = $fields[1]; # syntax error
$formalname{$fields[0]} = $fields[2]; # syntax error
$chapters{$fields[0]} = $fields[3]; # syntax error
}
print Dumper \%name;
print Dumper \%formalname;
print Dumper \%chapters;
__DATA__
01 +Genesis +The Book of Genesis +50
02 +Exodus +The Book of Exodus +40
03 +Leviticus +The Book of Leviticus +27
04 +Numbers +The Book of Numbers +36
05 +Deuteronomy +The Book of Deuteronomy +34
More information about the Houston
mailing list