It's a bit subtler than that.

When you write string literals, single-quoting them make them contain exactly the characters you typed, while double-quoting them activates the interpolation mechanism.

On the other hand, when you use a string as a regular expression, it gets interpreted by the regex engine.

For example:

$literal='abc@array$'; @array=(1,2,3); $interpolated="abc@array\$"; print 'literal: ',$literal,"\n"; print 'interp.: ',$interpolated,"\n"; if ($literal =~ /$literal/) { print "literal matches itself\n" } else { print "literal doesn't match itself\n" } $literal2='abc@array'; if ($literal2 =~ /$literal2/) { print "literal2 matches itself\n" } else { print "literal2 doesn't match itself\n" } if ($literal2 =~ /$literal/) { print "literal2 matches literal\n" } else { print "literal2 doesn't match literal\n" }

This prints:

literal: abc@array$ interp.: abc1 2 3$ literal doesn't match itself literal2 matches itself literal2 matches literal

The first two lines are hopefully obvious. As for the others:

OK, for the pedants: the string between the // is interpolated, but its contents are not further expanded. I felt that this was more noise than signal, in this case.
-- 
        dakkar - Mobilis in mobile

Most of my code is tested...

Perl is strongly typed, it just has very few types (Dan)


In reply to Re^3: substituted text is being interpreted by dakkar
in thread substituted text is being interpreted by j.goor

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.