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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|