in reply to extracting corresponding values from another array

From what I recall, it is ineffective to access list elements by index, if you have to check all elements - at least this is true for large lists. Therefore, the following might be an alternative:

my (@temps, @numbers); my ($ind, $maxind, $max) = (-1, -1, $num[0]); for my $num (@numbers) { $ind++; $maxind = $ind, $max = $num if $num > $max; } my $maxtemp = $temps[$maxind];

pike

Replies are listed 'Best First'.
Re: Re: extracting corresponding values from another array
by demerphq (Chancellor) on Dec 03, 2002 at 15:33 UTC
    From what I recall, it is ineffective to access list elements by index

    Any chance you might throw together a benchmark so we can see?

    Also, while your solution does distinguish between an empty list and the highest being at 0, it'll die on the last line if the array is empty.

    --- demerphq
    my friends call me, usually because I'm late....