I have just started learning Perl and this is my first Perl question. I'm working through "Learning Perl" and I've got a problem with strings. Specifically the difference b/t single-quoted and double-quoted strings and the use of the backslash character.

In the Single-quoted strings section it says that, "Any character other than a single quote or a backslash between the quote marks (including newline characters, if the string continues onto successive lines) stands for itself inside a string. To get a backslash, put two backslashes in a row, and to get a single quote, put a backslash followed by a single quote."

I tried the following:
print 'Testing\z'; print 'Testing\\n'; print 'Testing\\\n'; print "\n";
And get:
erikweibust@daleweibust ~/perl/lrn_perl $ ./test1-2.pl Testing\nTesting\nTesting\\n erikweibust@daleweibust ~/perl/lrn_perl $
So I'm scared that either the books wrong (please don't get the wrath of Randal Schwartz) or I'm missing something. I would have expected the output to be:
erikweibust@daleweibust ~/perl/lrn_perl $ ./test1-2.pl TestingnTesting\nTesting\n erikweibust@daleweibust ~/perl/lrn_perl $
Can anybody help clear this up?

Thanks,
Erik


In reply to Problem w/ single-quoted strings by eweibust

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.