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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.