in reply to slicing array based on values but not index
Giving:use warnings; use strict; use Data::Dumper; my @arr = ( [12, "abc", 30], [24, "abc", 30], [26, "abc", 30], [14, "abc", 40], [46, "abc", 40], [2, "abc", 50] ); my %res; map { push @{$res{$_->[2]}}, $_ } @arr; warn Dumper values %res;
$ perl tst.pl $VAR1 = [ [ 2, 'abc', 50 ] ]; $VAR2 = [ [ 14, 'abc', 40 ], [ 46, 'abc', 40 ] ]; $VAR3 = [ [ 12, 'abc', 30 ], [ 24, 'abc', 30 ], [ 26, 'abc', 30 ] ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: slicing array based on values but not index
by suggestsome (Initiate) on Aug 13, 2009 at 21:30 UTC | |
by Bloodnok (Vicar) on Aug 13, 2009 at 21:51 UTC | |
by suggestsome (Initiate) on Aug 13, 2009 at 22:32 UTC | |
by ikegami (Patriarch) on Aug 13, 2009 at 22:37 UTC | |
by Bloodnok (Vicar) on Aug 14, 2009 at 11:45 UTC |