Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Different hashes?

by tcf22 (Priest)
on Mar 26, 2004 at 15:04 UTC ( #340033=note: print w/replies, xml ) Need Help??


in reply to Different hashes?

You are overwriteing the key in %AllProducts every loop. You need to make the hash value an array ref then push onto it.

Try this:
foreach my $line(@ProductArray) { my ($Category, $ID, $Name, $Type, $Size) = split( / /, $line ); unless(exists $AllProducts{$Category}){ $AllProducts{$Category} = []; } push(@{$AllProducts{$Category}}, $ID, [$Name, $Type, $Size]); print OUTPUT Dumper(\%AllProducts); }

- Tom

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://340033]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2020-06-03 05:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (21 votes). Check out past polls.

    Notices?