in reply to slicing array based on values but not index

You mean something like:
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;
Giving:
$ perl tst.pl $VAR1 = [ [ 2, 'abc', 50 ] ]; $VAR2 = [ [ 14, 'abc', 40 ], [ 46, 'abc', 40 ] ]; $VAR3 = [ [ 12, 'abc', 30 ], [ 24, 'abc', 30 ], [ 26, 'abc', 30 ] ];
A user level that continues to overstate my experience :-))

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
    Kudos!!!

    Please excuse my poor knowledge, can you explain how is it working?
      map { push @{$res{$_->[2]}}, $_ } @arr;
      map loops thro' all values of the array @arr - setting $_ to each value (an array ref.) in turn - pushing that value onto an array in a hash keyed on the last element of each individual array.

      As you can see, the result you're interested in is the array of values of the newly created hash.

      A user level that continues to overstate my experience :-))
        @ Bloodnok:

        Thank you very much, :).