20050119: quoting strings

X

Xah Lee

#strings are enclosed in double quotes quotes. e.g.
a="this and that"
print a

#multiple lines must have an escape backslash at the end:
b="this\n\
and that"
print b

#One can use r"" for raw string.
c=r"this\n\
and that"
print c

#To avoid the backslash escape, one can use triple double quotes to
print as it is:
d="""this
and
that"""
print d

---------------
# in Perl, strings in double quotes acts as Python's triple """.
# String is single quote is like Python's raw r"".
# Alternatively, they can be done as qq() or q() respectively,
#and the bracket can be just about any character,
# matching or not. (so that escapes can be easy avoided)

$a=q(here, everthing is literal, $what or \n or what not.);
$b=qq[this is
what ever including variables $a that will be
evaluated, and "quotes" needn't be quoted.];
print "$a\n$b";

#to see more about perl strings, do on shell prompt
#perldoc -tf qq
Xah
(e-mail address removed)
http://xahlee.org/PageTwo_dir/more.html
 
S

Steve Holden

Xah said:
#strings are enclosed in double quotes quotes. e.g.
a="this and that"
print a

#multiple lines must have an escape backslash at the end:
b="this\n\
and that"
print b

#One can use r"" for raw string.
c=r"this\n\
and that"
print c

#To avoid the backslash escape, one can use triple double quotes to
print as it is:
d="""this
and
that"""
print d

---------------
# in Perl, strings in double quotes acts as Python's triple """.
# String is single quote is like Python's raw r"".
# Alternatively, they can be done as qq() or q() respectively,
#and the bracket can be just about any character,
# matching or not. (so that escapes can be easy avoided)

$a=q(here, everthing is literal, $what or \n or what not.);
$b=qq[this is
what ever including variables $a that will be
evaluated, and "quotes" needn't be quoted.];
print "$a\n$b";

#to see more about perl strings, do on shell prompt
#perldoc -tf qq
Xah
(e-mail address removed)
http://xahlee.org/PageTwo_dir/more.html

Well, that gets that sorted out, then.

Tomorrow: using single quotes. Using single quotes. The larch.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top