LanX has asked for the wisdom of the Perl Monks concerning the following question:
I have a hard time finding this behaviour documented in perldoc.
The following example is showing that "\x" and "\xx" are interpreted as octal code points in ASCII when used in string interpolation ( with x in 0..7)
DB<25> for (0..20) { $a= eval qq{"\\$_"}; print "\\$_: ",ord($a),"\n +";} \0: 0 \1: 1 \2: 2 \3: 3 \4: 4 \5: 5 \6: 6 \7: 7 \8: 56 \9: 57 \10: 8 \11: 9 \12: 10 \13: 11 \14: 12 \15: 13 \16: 14 \17: 15 \18: 1 \19: 1 \20: 16
The best I found is: (but only after realising it's octal)
perlrebackslash#Octal%20escapes
> In some contexts, a backslash followed by two or even one octal digits may be interpreted as an octal escape, sometimes with a warning, and because of some bugs, sometimes with surprising results.
Please note that perlrebackslash is supposed to describe escape sequences in regexes and not in general string interpolations.
Additionally does s/(PATTERN)/\1/ have a very different meaning in regexes (backreference of a matching group)
Is there a better perldoc to find the behaviour in normal "strings" explained?
Any canonical / obvious starting point for "string interpolation"?
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
non octal sequences in the above example (like "\8" and "\18") will create warnings (if enabled).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perldoc: String interpolation with octal escpape sequence like \1
by choroba (Cardinal) on Oct 02, 2018 at 15:13 UTC | |
by Eily (Monsignor) on Oct 02, 2018 at 15:18 UTC | |
by LanX (Saint) on Oct 02, 2018 at 15:31 UTC | |
by LanX (Saint) on Oct 02, 2018 at 15:29 UTC | |
|
Re: Perldoc: String interpolation with octal escpape sequence like "\1" (perlquote)
by Anonymous Monk on Oct 05, 2018 at 01:46 UTC |