I don't believe this would work. Firstly,
Doesn't matter, poulate @explicit however you like
Secondly, Will ensure the store(i.e the key) will only have the last product read from the input.
Is this important?
This is how you're supposed to use map, to create lists -- if you're not doing that stick with foreach (or to save memory stick with while)
If all you want is to treat it like foreach, you can use it in void context, but its not recommended, it clouds the purpose, and on older perls its not efficient
#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; open my($fh),'<', \<<'__FUDGE__' or die; STORE PRODUCT_ID ==================== Sydney 12 Sydney 14 Canberra 12 Canberra 18 __FUDGE__ my %hash; $hash{(split)[0]}{(split)[1]} = 1 while <$fh>; seek $fh, 0, 0; dd\%hash; undef %hash; map { my @explicit = split ' ', $_; 2 == @explicit ## ==== and $hash{ $explicit[0] }{ $explicit[1] }++; (); } <$fh>; dd\%hash; __END__ $ perl fudge Use of uninitialized value in hash element at fudge line 16, <$fh> lin +e 6. { "====================" => { "" => 1 }, "Canberra" => { 12 => 1, 18 => 1 }, "STORE" => { PRODUCT_ID => 1 }, "Sydney" => { 12 => 1, 14 => 1 }, } { Canberra => { 12 => 1, 18 => 1 }, STORE => { PRODUCT_ID => 1 }, Sydney => { 12 => 1, 14 => 1 }, }
In reply to Re^5: Possible for Map to create Hash of Hash?
by Anonymous Monk
in thread Possible for Map to create Hash of Hash?
by konnjuta
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |