in reply to create hash with map
%cp_samp=map {$_} split/:/, $sy;
is the same thing as
%cp_samp=split/:/, $sy;
foreach $sy (@ex_array) { %cp_samp=map {$_} split/:/, $sy; }
is the same thing as
%cp_samp=split/:/, $ex_array[-1] if @ex_array;
which produces neither what you want nor what you said is produced.
Finally, may I recommend a HoA ($cp_samp{sample1}[0]=3 $cp_samp{sample1}[1]=4 ..) instead of a HoH?
my %cp = map { my ($label, $list) = (split(/:/), ''); $label => [ split /,/, $list ] } @ex;
Update: By the way, the for version would be
my %cp; foreach (@ex) { my ($label, $list) = (split(/:/), ''); $cp{$label} = [ split /,/, $list ]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: create hash with map
by Anonymous Monk on Sep 24, 2007 at 09:07 UTC |