Monday, September 13, 2010

Escape character in perl

There's something else new in the code above. The \ . You can see what this does -- it 'escapes' the special meaning of $ .
Escaping means that just the $ symbol is printed instead of it referring to a variable.
Actually \ has a deeper meaning -- it escapes all of Perl's special characters, not just $ . Also, it turns some non-special characters into something special. Like what ? Like n . Add the magic \ and the humble 'n' becomes the mighty NewLine ! The \ character can also escape itself. So if you want to print a single \ try:
print "the MS-DOS path is c:\\scripts\\";   
Oh, '\' is also used for other things like references.

No comments:

Post a Comment