What's the difference between single and double quotes in Perl?

interpolation, perl, syntax

Solution

I am inclined to say something is up with your shell/terminal, and whatever you are outputting to is interpreting the \n as a newline and that the problem is not with Perl.

To confirm: This Shouldn't Happen(TM) - in the first case I would expect to see a new line inserted, but with single quotes it ought to output literally the characters \n and not a new line.

Problem

I am just begining to learn Perl. I looked at the beginning perl page and started working. It says: The difference between single quotes and double quotes is that single quotes mean that their contents should be taken literally, while double quotes mean that their contents should be interpreted When I run this program: ``` #!/usr/local/bin/perl print "This string \n shows up on two lines."; print 'This string \n shows up on only one.'; ``` It outputs: ``` This string shows up on two lines. This string shows up on only one. ``` Am I wrong somewhere? the version of perl below: ``` perl -v This is perl, v5.8.5 built for aix Copyright 1987-2004, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using `man perl' or `perldoc perl'. If you have access to the Internet, point your browser at http://www.perl.com/, the Perl Home Page. ```

Original source