In scalar context, returns the number of times the expression was true.
and it's $i3 not i3
anyway others may profit from a working solution, just replacing grep with first
use strict; use warnings; use List::Util qw/first/; my @array=(1,2); my $i1 = first { $array[$_] == 1 } (0..$#array); my $i2 = first { $array[$_] == 2 } (0..$#array); my $i3 = first { $array[$_] == 3 } (0..$#array); print "<$i1> <$i2> <$i3>\n";
Use of uninitialized value $i3 in concatenation (.) or string at d:/tm +p/first.pl line 13. <0> <1> <>
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
In reply to Re: grep surprise
by LanX
in thread grep surprise
by morgon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |