Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thanks in advance.# WRONG { my %hash; my @cols = qw(min max sum); my @values = qw(1 3 4); @hash{@cols} = @values; use Data::Dumper; print Dumper \%hash; } # CORRECT (but slow) { my %hash; my @cols = qw(min max sum); my @values = qw(1 3 4); foreach my $col (@cols) { push @{$hash{$col}}, shift @values; } use Data::Dumper; print Dumper \%hash; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Creating hash of arrays (in a faster way)
by BrowserUk (Patriarch) on Nov 01, 2013 at 11:00 UTC | |
|
Re: Creating hash of arrays (in a faster way)
by choroba (Cardinal) on Nov 01, 2013 at 09:35 UTC | |
by Corion (Patriarch) on Nov 01, 2013 at 09:57 UTC | |
by Anonymous Monk on Nov 01, 2013 at 10:33 UTC | |
|
Re: Creating hash of arrays (in a faster way)
by Laurent_R (Canon) on Nov 01, 2013 at 11:20 UTC | |
|
Re: Creating hash of arrays (in a faster way)
by LanX (Saint) on Nov 01, 2013 at 13:21 UTC |