[pm-h] hash creation - syntax error

Russell L. Harris rlharris at oplink.net
Sat May 10 14:15:00 PDT 2008


The Perl compiler is complaining of syntax errors in the three
statements indicated below.

I am attempting to create a set of three hashes, keyed to the sequence
number of the books of the Bible.

The data with which I am trying to populate the hatches comes from the
file "sequence-name-name-chapters', which has lines of the form:

    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

Here is the Perl script:

# -----------------------------------------------------------

my $snnc = "";
my @fields = ();

open(my $fh, '<', 'sequence-name-name-chapters' ) 
  or die "unable to open 'sequence-name-name-chapters': $!";
chomp( my @snnc = <$fh> );

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";

        my $name{"$fields[0]"} = $fields[1]; # syntax error
  my $formalname{"$fields[0]"} = $fields[2]; # syntax error
    my $chapters{"$fields[0]"} = $fields[3]; # syntax error

}

# -----------------------------------------------------------

The print commands are only for diagnostic use; they produce the
following listing:

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

# -----------------------------------------------------------

I am a Perl novice.  I welcome recommendations as to alternative
approaches.

RLH


More information about the Houston mailing list