Probably referring to the magic of: if you use an empty pattern then the last successfull pattern match is re-used. Doesn't show up in your example, but could catch someone unawares:

#!/usr/bin/perl -w use strict; # this messes up the intended empty pattern later: $_ = 'match'; /m/; my $prefix = 'dog'; my %hash = map {++$;,$_} (qw(ged house ma matic),''); print "Before:\n"; print "$_ => '$hash{$_}'\n" for keys %hash; s//$prefix/for values%hash; # Add the Prefix... print "\nAfter:\n"; print "$_ => '$hash{$_}'\n" for keys %hash; __END__ output: Before: 1 => 'ged' 2 => 'house' 3 => 'ma' 4 => 'matic' 5 => '' After: 1 => 'ged' 2 => 'house' 3 => 'doga' 4 => 'dogatic' 5 => ''

That could be easily fixed by using s/^/$prefix/ rather than the empty pattern in this case.

Update: just for reference, the relevant documentation is in perlfunc under the /PATTERN/cgimosx operator:

If the PATTERN evaluates to the empty string, the last successfully matched regular expression is used instead.

In reply to Re: Re5; Is a global variable better than repetition within variables? by danger
in thread Is a global variable better than repetition within variables? by c

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.