Nano's Blog

01/05/2010

Single Quoted String Literals VS Double Quoted String Literals

Filed under: programming — Tags: — nano @ 07:39

Single-Quoted String Literals.

A single-quoted string literal is a sequence of characters enclosed in single quotes. The single quotes are not part of the string iteself.
‘hello\n’ # hello followed by backslash followed by n

Double-Quoted String Literals

It’s a sequence of characters, although this time enclosed in double quotes. But now the backslash takes on its full power to specify certain control characters.
“hello\n” # hello, and a newline

If you wish to use backslash escape(like \n to mean a newline character), you will need to use the double quotes.

- from Leaning Perl 5E

Sample code

#!C:\Perl\bin\perl.exe
use strict;
use warnings;

print '\'\\';
print "\n";
print 'Hello World!\n';
print "\n";
print "Hello World!\n";

Output

'\
Hello World!\n
Hello World!

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress