PLEASE DON'T USE $&! Take a look at perldoc perlvar for $&. For why $& is generally consider to be a Bad Thing™, check out the documentation for Devel::SawAmpersand. The important parts:

There's a global variable in the perl source, called sawampersand. It gets set to true [..whenever..] the parser sees one of $`, $', and $&. It never can be set to false again.

If the global variable sawampersand is set to true, all subsequent RE operations will be accompanied by massive in-memory copying, because there is nobody in the perl source who could predict, when the (necessary) copy for the ampersand family will be needed. So all subsequent REs (even in places outside of scope) considerably slower than necessary.

That page even offers helpful ways that you can avoid the $&, $`, and $' variables.

Update: Proof of concept since my buddy didn't believe me:

Introducing Test1.pm

package Test1; use Devel::SawAmpersand qw(sawampersand); use Exporter; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = qw(testbelow); sub testbelow { print "Inside Test1::testbelow"; print "sawampersand? ", (sawampersand() ? "yes":"no"); print "Outside Test1::testbelow" } 1;

Introducing Test2.pm

package Test2; use Exporter; our @ISA = qw(Exporter); # notice that we don't even export anything sub showdollaramp { $&; } 1;

And test.pl

use Test1; use Devel::SawAmpersand qw(sawampersand); $\ = "\n"; # I'm lazy; puts \n at end of every print print "sawampersand? ", (sawampersand() ? "yes":"no"); testbelow(); require Test2; print "Loaded Test2"; print "sawampersand? ", (sawampersand() ? "yes":"no"); testbelow(); __DATA__ output: sawampersand? no Inside Test1::testbelow sawampersand? no Outside Test1::testbelow Loaded Test2 sawampersand? yes Inside Test1::testbelow sawampersand? yes Outside Test1::testbelow

So will this affect anything anywhere else including within modules that loaded prior to the $& showing up? YES!

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1


In reply to Good God Man! Don't do it! by antirice
in thread appending to end of string by jc23

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.