in reply to Re: Re: Getting last valid index from a particular list in a @LoL
in thread Getting last valid index from a particular list in a @LoL

use List::Util qw(max); my $max = max (map $#$_, @LoL);

-- Randal L. Schwartz, Perl hacker


update Bah, I didn't read. {grin}

OK, this instead:

use List::Util qw(max); my $max = max (map $#$_, @LoL); my @where = grep $#{$LoL[$_]} == $max, 0..$#LoL;
{grin}

Replies are listed 'Best First'.
Re: Re: Re: Re: Getting last valid index from a particular list in a @LoL
by blakem (Monsignor) on Oct 17, 2001 at 04:16 UTC
    That gives last index *in* the longest array, not the index *of* said array, which is what was asked for. In otherwords, he's trying to locate the longest array, not necessarily find out how long it is.

    Update: merlyn's new code address the issue, nicely....

    -Blake

Re^4: Getting last valid index from a particular list in a @LoL
by Aristotle (Chancellor) on Oct 17, 2001 at 07:40 UTC
    Aren't you tying your leg to your cheek there by going through the array twice? :-/

    It's irrelevant when the script is going to be thrown away two days later of course, but I'd never put any bets on that. "A little" sloppiness here and "a little" there and some more at another place tends to pile up faster than you notice..
      I'll bet you that for a 10-50 element list, my method to find all points which have a maximum beats any method where you do all the bookkeeping yourself. List::Util::max and grep are darn fast.

      -- Randal L. Schwartz, Perl hacker

        Ah, point, when there are several "equally longest" lists.