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:

A B C
But the output of #3 is:
F T E

Can anyone help me figure out why?

Thanks, -tl


In reply to problem with hash keys by june_bo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.