Q:\>perl -le "($x = 'foo') =~ /.(.)/g; print $1; $x = 'bar'; print $1" o a
wow. didn't expect that.

betterworld and i just tried out some other examples, and it seems that the string buffer is not really emptied.

$ perl -MData::Dumper -we'$Data::Dumper::Useqq = 1; ($x = "fou") =~ /.(..)/g; print Dumper $1; $x = "b"; print Dumper $1; ' $VAR1 = "ou"; $VAR1 = "\0u"; $ perl -MData::Dumper -we'$Data::Dumper::Useqq = 1; ($x = "fou") =~ /.(..)/g; print Dumper $1; $x = "ba"; print Dumper $1; ' $VAR1 = "ou"; $VAR1 = "a\0";
so $1 just outputs the second and third character of the string, and in the first example you see the remains of the string 'fou'

In reply to Re^2: Things you should need to know before using Perl regexes. (Humour, with a serious point) by tinita
in thread Things you should need to know before using Perl regexes. (Humour, with a serious point) by BrowserUk

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.