in reply to grep surprise
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: grep surprise
by morgon (Priest) on Nov 11, 2018 at 23:52 UTC | |
by LanX (Saint) on Nov 12, 2018 at 13:46 UTC | |
by dbuckhal (Chaplain) on Nov 12, 2018 at 18:37 UTC | |
|