I piping in a file with multiple records and storing these records in a hash after they are split into an array. If I use Data Dumper I can see all of the data I've put in but when I try to loop through the hash to get individual elements I get nothing. The foreach loop I'm using is being ignored completely.


Here is an example of the array record inserted into the hashref and the ineffective loop.
The Data Dumper line just before the loop shows me all the hash data as expected.
Where am I going wrong?
my ($share_hash, %share_hash, @fields); while (<>) { @fields = split(/\|/,$_,-1); $share_hash{$fields[$colhash{res_stay_id}]} = [@fields]; print Dumper(%share_hash); foreach my $share_item (keys %$share_hash) { my $row = $share_hash->{$share_item}; print STDOUT join("|", @$row), "\n"; } }

Sample input
X|156853|2012-09-11 10:10:51|2012-09-10|LQ|NVCORP|0570|2012-09-06|2012-09-11|2012-09-06||1|1|0|USD|47.50|237.50|.00|DDR|N|93446|PASO ROBLES|CA|||N||N|Contract/Crew|CC2|101|101|Walk In|WERNER|158167|156853 X|156855|2012-09-11 10:10:51|2012-09-10|LQ|NVCORP|0570|2012-09-06|2012-09-10|2012-09-06||1|1|0|USD|47.50|190.00|95.00|DDR|N|93230|HANFORD|CA|||N||N|Contract/Crew|CC2|101|101|Walk In|WERNER|158167|156853 X|157155|2012-09-11 10:10:51|2012-09-10|LQ|NVCORP|0570|2012-09-10|2012-09-11|2012-09-10||1|1|0|USD|47.50|47.50|.00|DDR|N|90008|LOS ANGELES|CA|||N||N|Contract/Crew|CC2|100|100|Property Direct|WERNER|158167|156853 X|156854|2012-09-11 10:10:51|2012-09-10|LQ|NVCORP|0570|2012-09-06|2012-09-10|2012-09-06||1|1|0|USD|47.50|190.00|95.00|DDR|N|90008|LOS ANGELES|CA|||N||N|Contract/Crew|CC2|101|101|Walk In|WERNER|158168|156854 X|156861|2012-09-11 10:10:51|2012-09-10|LQ|NVCORP|0570|2012-09-06|2012-09-10|2012-09-06||1|1|0|USD|47.50|237.50|95.00|DDR|N|97007|ALOHA|OR|||N||N|Contract/Crew|CC2|100|100|Property Direct|WERNER|158168|156854 X|156934|2012-09-11 10:10:51|2012-09-10|LQ|NVCORP|0570|2012-09-07|2012-09-10|2012-09-07||1|1|0|USD|47.50|95.00|142.50|KP|N|84128|WEST VALLEY|UT|||N||N|Contract/Crew|CC2|101|101|Walk In|WERNER|158248|156934

Thanks for the help. After clarifying the variables I was using I was able to get the output I wanted. Unfortunately I work with some folks who like to make their Perl code as confusing as possible so they name their variable all the same.


In reply to hashes hash refs and arrays by brcjacks

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.