Please note in your node any substantive changes that you make (changing the code is a substantive change).

Actually once the variable name problem was fixed my earlier sample code wasn't so good. However the following revised code works as expected:

use strict; use warnings; my @_lines = map {"$_\n"} split /\n/, <<LINES; ABC in the first line but not the second LINES foreach my $line (@_lines) { my $templine = $line; print "$templine"; # or print "$line"; if ($templine =~ /(ABC)/) {print "$1 = the line (1)\n";} } foreach my $_line (@_lines) { my $templine = $_line; ############ print "$templine"; ############ # or print "$line"; if ($templine =~ /(ABC)/) {print "$1 = the line (2)\n";} }

Prints:

ABC in the first line ABC = the line (1) but not the second ABC = the line (2)

If this is showing your failure mode then I don't understand what the problem is. If it doesn't show your failure mode then modify my sample code until it does and post the updated code along with the "bad" output.

True laziness is hard work

In reply to Re^3: Printing the variable makes the next match code work. Why? by GrandFather
in thread Printing the variable makes the next match code work. Why? by scaryfast

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.