reaper9187 has asked for the wisdom of the Perl Monks concerning the following question:
The above code checks the each 'row' of the 2D array and extracts those arrays(1D)/entries if any of the column entries is greater than the threshold( in this case, 6). I would like to able to set multiple checks across multiple columns,i.e. for eg: extract rows for which the second column entry > 4 and 4th column entry > 3 and so on.use strict; use warnings; use Data::Dumper; my @arr; @arr = ( [ 'A', 1, 0, 5, 6, 2 ], [ 'B', 3 , 4 , 5 , 6 , 7 ], [ 'C' , 2 , 4 ,3 ,5 ], [ 'D' , 6 , 7 , 8 ,8 ], [ 'E' , 2 , 5 , 4 , 5 ], [ 'F' , 4 , 3 , 2 ,2 ], [ 'G' , 1 , 2 , 4, 5 ], [ 'H' , 1 , 4 , 5, 6 ] ); my @rows = grep { grep {$_ > 6} @$_ } @arr; print Dumper(\@rows);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simplest way to match/filter 2d array of values to search in perl
by kennethk (Abbot) on Jul 03, 2014 at 20:33 UTC | |
by reaper9187 (Scribe) on Jul 03, 2014 at 20:47 UTC | |
|
Re: Simplest way to match/filter 2d array of values to search in perl
by AnomalousMonk (Archbishop) on Jul 03, 2014 at 22:45 UTC | |
|
Re: Simplest way to match/filter 2d array of values to search in perl
by reaper9187 (Scribe) on Jul 04, 2014 at 09:51 UTC | |
by AppleFritter (Vicar) on Jul 04, 2014 at 10:22 UTC |