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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |