This may be another case of missing the forest for the trees, but what is going on in the version in lines 27-30?
#!/usr/bin/perl use warnings; use strict; # [id://863649] print "\n\t First test: incorporating correction by ikegami\n"; my @array = qw( testme foo bar ); my $i = 1; for my $string(@array) { my $test = $string; my $string2 = qq! first ! . (grep /$test/, $string) ? qq! yes ! : +qq! no ! . qq! end !; print "\$test: $test | \$string: $string | \$string2: $string2 | $ +i \n"; $i++; } print "\n\t now testing with 'blivitz'\n"; for my $string(@array) { my $test = "blivitz"; my $string3 = (grep /$test/, $string) ? qq! yes ! : qq! no !; print "\$test: $test | \$string3: $string3 | $i \n"; $i++; } print "\n\t BUT...\n"; my $string = qq! first ! . (grep /blivitz/, @array) ? qq! yes ! : qq! no ! . qq! end !; print $string . " -last test, lines 27-30 \n"; =head OUTPUT of 863649.pl as corrected by [ikegami] and extended First test: incorporating correction by ikegami $test: testme | $string: testme | $string2: yes | 1 $test: foo | $string: foo | $string2: yes | 2 $test: bar | $string: bar | $string2: yes | 3 now testing with 'blivitz' $test: blivitz | $string3: no | 4 $test: blivitz | $string3: no | 5 $test: blivitz | $string3: no | 6 BUT... yes -last test, lines 27-30 =cut
WTF?!? grep is finding "blviitz" in @array? (or, ww is having another senior moment?)
In reply to Re^2: Grep-Ternary Operator Question
by ww
in thread Grep-Ternary Operator Question
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |