DB<109> @a= map { int rand 100 } 1..10
=> (96, 10, 99, 9, 43, 8, 20, 85, 42, 26)
DB<110> sub minindex {
my @x=@_;
reduce { $x[$a] < $x[$b] ? $a : $b } 0 .. $#_
}
DB<111> print minindex @a
5
update
or even better like ikegami now suggested as ref to avoid overhead
DB<114> @a= map { int rand 100 } 1..10 => (22, 15, 27, 44, 70, 85,
+74, 93, 96, 14)
DB<115> sub minindex {
my $x=\@_;
reduce { $x->[$a] < $x->[$b] ? $a : $b } 0 .. $#_
}
DB<116> print minindex @a
9
Cheers Rolf
( addicted to the Perl Programming Language)
|