Just another Perl shrine | |
PerlMonks |
Re^7: Escaping multiple escape charsby ikegami (Patriarch) |
on Dec 12, 2005 at 15:50 UTC ( [id://516036]=note: print w/replies, xml ) | Need Help?? |
However, 'some\\text' and "some\\text" don't behave as you would expect I got the following (abbreiviated) results:
If you obtained the above, perl behaved as expected (or at least as documented). According to to the relevant docs, double-quoted string literals are subject to backslash and variable substitution; single-quoted strings are not (except for \' and \\). In single quotes, perl interprets the backslash literally (instead of an escape) unless followed by another backslash or by a single quote. This DWIM most of the time, since few characters ever need to be escaped in single-quoted strings. For example, '\n' results in the string {backslash}+{lowercase n}. In double quotes, perl interprets the backslash and the following character as an escape (instead of literally). How perl interprets an invalid/unrecognized escape sequence is undocumented (or unclearly documented), but the behaviour has consistently been to replace the escape sequence with the character that followed the backslash. This DWIM most of the time, since the extra backslash was probably a case of overzealous escaping. For example, "\<" results in the string {right angle bracket}. If you don't see the necessity of the equivalency of
In Section
Seekers of Perl Wisdom
|
|