[Courses] [Perl] A bit of clarification on what Alice said about quotes

Morgon Kanter morgon at surgo.net
Sat Mar 15 12:35:39 EST 2003


> Note the use of quotes here. The single quote (') indicates that the text will 
> be used verbatim and the double quote (") indicates the text will be 
> interpreted.

This would be a bit confusing for me, so let me clarify.

A string enclosed ' ' means it is literally what you put it. Any character 
other than a single quote or a backslash-single-quote (\') stands for itself 
inside of the string.

$var = ' '	# A string with one space
$var = '\''	# A string with a single quote inside of it
$var = 'yo\n'	# A string with yo followed by a \n
$var = 'te
st'		# A string that reads te NEWLINE st

Now on the other hand, in a double-quoted string, you can use escape characters 
etc like in C and other languages. Here is a brief list.

\n	# Newline
\r	# Return
\t	# Tab
\f	# Form feed (AKA page breaks on some printers)
\b	# Backspace
\a	# Rings the bell!
\e	# Escape (think of the escape key on your keyboard)
\\	# Backslash
\"	# Double quotes
\'	# Single quote in a single-quoted string
\l	# Lowercase next letter
\L	# Lowercase all the following letters until a \E
\u	# Uppercase next letter
\U	# Same as \L but uppercases
\Q	# Quote non-word characters by adding a \ until a \E is read
\E	# Terminates \L, \U and \Q
\xyz	# Any character's octal value
\xFF	# Any character's hex value
\cC	# A so-called "control" character, in this example ^C (ctrl-C)

so...
$var = "yo"	# The string reads yo
$var = "yo\n"	# The string reads yo NEWLINE

I hope that cleared some things up for any that were confused

Morgon


More information about the Courses mailing list