in reply to Shortest -return index of element in array- sub
How about
retaining jmcnamara comments about golfsub indexArray{for(1..@_){$_[0]eq$_[$_]&&return$_-1}-1} my @array=('john','paul','ringo','george'); print indexArray('john',@array) ."\n"; # Returns 0 print indexArray('ringo',@array) ."\n"; # Returns 2 print indexArray('mick',@array) ."\n"; # Returns -1
|
---|
Replies are listed 'Best First'. | |
---|---|
Re (tilly) 1: Shortest -return index of element in array- sub
by tilly (Archbishop) on Mar 22, 2001 at 05:57 UTC |
In Section
Cool Uses for Perl