in reply to Re: How can I find the index of the biggest element in an array?
in thread How can I find the index of the biggest element in an array?
I don't think it's good to scare people with a ternary operator and statement modifier in one statement. I do think
would be much more readable. I'd probably write it like this though:while ($i--) { $max = $i if $data[$i] > $data[$max]; }
my $max = 0; for (0 .. $#data) { $max = $_ if $data[$_] > $data[$max] }
Update (suggested by ysth): It's actually better to start looping at index 1:
There's no point in comparing the first element to itself.my $max = 0; for (1 .. $#data) { $max = $_ if $data[$_] > $data[$max] }
|
---|
In Section
Seekers of Perl Wisdom