june_bo has asked for the wisdom of the Perl Monks concerning the following question:
Writing a program for my compilers class.
Using these input files
input file 1:
A -> Aa | B | C | EMPTY
B -> Ab | C
C -> m
input file 2:
A -> BCj | gDB
B -> bCDE | EMPTY
C -> DaB | ma | DB
D -> dD | EMPTY
E -> gAf | i
input file 3:
E -> E+T | T
T -> T*F | F
F -> (E) | a
Here is the code that is giving me trouble
while(<INFILE>){ chomp(); m/([A-Z]) -> (.*)/; # take the line, put the righthand side # into $1, put lefthand side into $2 $GRAMMAR{$1} = $2; # enter into hash table GRAMMAR } print "gonna print some info: \n"; while(($k, $v) = each %GRAMMAR) { print "$k\n"; }
Input file 1 and 2 create hash tables with the keys in the order of the input file. The output of #1, for example, is:
But the output of #3 is:A B C
F T E
Can anyone help me figure out why?
Thanks, -tl
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: problem with hash keys
by btrott (Parson) on Jun 17, 2001 at 07:13 UTC | |
by june_bo (Novice) on Jun 17, 2001 at 07:25 UTC | |
by ariels (Curate) on Jun 17, 2001 at 15:34 UTC | |
Re: problem with hash keys
by wog (Curate) on Jun 17, 2001 at 07:13 UTC | |
Re: problem with hash keys
by marcink (Monk) on Jun 17, 2001 at 07:13 UTC |
Back to
Seekers of Perl Wisdom