3.3.1. Escape Sequences
We have already encountered the \n "escape sequence" which can come inside strings and designates a newline character. There are many others in perl. Here is a list of the most important ones:
- \\ - designates an actual backslash (\)
- \" - designates an actual double-quote character (")
- \$ - an actual dollar sign (a real $ does something else)
- \@ - an actual at-sign (a non-escaped @ does something else)
- \n - a newline character
- \r - a carriage return sign
- \t - a tab character
- \xDD - where "DD" are two hexadecimal digits - gives the character whose ASCII code is "DD".
Here's an example to illustrate some of them:
print "I said \"hi!\" to myself, and received no reply.\n"; print "This program will cost you \$100 dollars.\n"; print "The KDE\\GNOME holy war makes life in the Linux world " . "more interesting.\n";
whose output is:
I said "hi!" to myself, and received no reply. This program will cost you $100 dollars. The KDE\GNOME holy war makes life in the Linux world more interesting.