Hello monks,
I have a question, concerning something i dont have any prior knowledge with, and since i am at home, not at my dorm, no access to my books :(. Here is my question, i am making a hash, in this hash has 5 keys, ill show you below:
%rec = (state => $part1[0], char => $part1[1], stack_char => $part1[2], new_state => $part2[0], new_stack_char => $part2[1]); push (@db, %rec);
this is in a loop, which defines every line in a file. Each line has a state, a char, a stack_char,.. you get the idea, and then this hash is pushed into an array. this is how i am trying to call it, but with no luck, using -w i get the following error:

" Odd number of elements in hash list at p2.pl line 68, <> chunk 8 "

Here is the code:
foreach $hash(@db){ %temphash = $hash; foreach $key( keys %temphash){ print "KEY: $key \n"; print "VALUE: $temphash{$key} \n"; print "________________________\n"; } #end foreach $key }#end foreach $hash
i assume this isnt really the way to define the hash per value in the array, but.. how can i do this??

Thank you very much in advance

2001-03-11 Edit by Corion : Moved to SOPW (who approved this for discussion ?)


In reply to Hash Array Help by Anonymous Monk

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.