Perhaps the following will be helpful:
use strict; use warnings; use Data::Dumper; my @masterArray = ( [ "this", "that", 12563, "something", "else" ], [ "this", "that", 10, "something", "else" ], [ "this", "that", 1, "something", "else" ], [ "this", "that", 125638, "something", "else" ], [ "this", "that", 300000, "something", "else" ], ); subDiscarder( \@masterArray ); print Dumper \@masterArray; sub subDiscarder { my ($arrayRef) = @_; my %nums = map $_ => 1, ( sort { $b <=> $a } map $_->[2], @$arrayRef )[ 0 .. 2 ]; @$arrayRef = grep exists $nums{ $_->[2] }, @$arrayRef; }
Output:
$VAR1 = [ [ 'this', 'that', 12563, 'something', 'else' ], [ 'this', 'that', 125638, 'something', 'else' ], [ 'this', 'that', 300000, 'something', 'else' ] ];
The subroutine sorts and then takes the top three largest 'minion' numbers to populate a hash, then greps through the 'master' array to allow only the three 'minion' arrays pass which contain one of those three top values.
In reply to Re: sorting array of arrays reference
by Kenosis
in thread sorting array of arrays reference
by kimlid2810
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |