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
And just for the fun of it, a bit faster if you have a couple hundred thousand lists in the list at the cost of extra clutter :-) :#!/usr/bin/perl -wT use strict; my @lol = ([1,2,3], [1,2,3,4,5], [1,2,3,4,5,6,7,8], [1,2,3,4], [1,2,3,4,5,6], ); my $index = 0; $index = $#{$lol[$index]} < $#{$lol[$_]} ? $_ : $index for 0 .. $# +lol; print "\$aoa[$index] has the most elements\n"; =OUTPUT $aoa[2] has the most elements
I'm still trying to figure out what blakem was thinking btw..my ($index,$len) = (0,0); $index = $len < $#{$lol[$_]} ? do { $len = $#{$lol[$_]}; $_ } : $i +ndex for 0 .. $#lol;
|
|---|