in reply to help with an array of arrays

TIMTOWTDI :)

Since you like List::Util here a more functional approach.

use strict; use warnings; use Data::Dump qw/pp dd/; use List::Util qw(min max); my @AoA = ( ["nick","99"], ["john","88"], ["peter","77"], ["thomas","99"] ); my @numbers=(99, 88, 77, 88); my $max = max(@numbers); pp map { $_->[0] } grep { $_->[1] == $max } @AoA;

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^2: help with an array of arrays
by choroba (Cardinal) on Sep 15, 2018 at 08:51 UTC
    > a more functional approach

    my @numbers = map $_->[1], @AoA;
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      better?

      use strict; use warnings; use Data::Dump qw/pp dd/; use List::Util qw(min max); use constant { name=>0, num=>1 }; my @AoA = ( ["nick","99"], ["john","88"], ["peter","77"], ["thomas","99"] ); my $max_num = max map { $_->[num] } @AoA; my @max_names = map { $_->[name] } grep { $_->[num] == $max_num } @AoA; pp @max_names;

      and for completeness another variant

      my @max_names = map { $_->[num] == $max_num ? $_->[name] : () } @AoA;

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        A question on this if I may:
        is it possible to do something similar to foreach for arrays, in array of arrays?. I mean, in the following code:
        my $min_diff_past = max (@all_date_diffs_past); for my $j ( 0 .. $#AoA_past ) { if ($AoA_past[$j][1]==$min_diff_past) { print $AoA_past[$j][0]."\t"; } }

        is there a way to not write the for loop but substitute it with a foreach loop or not?