Skip to content

Commit 9c6fadc

Browse files
authored
Merge pull request #48 from leonerd/ppc0019-clarify-escapes
PPC0019: Add some clarifying words to explain how escapes are handled
2 parents 3b5d04b + 00ff9b7 commit 9c6fadc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

ppcs/ppc0019-qt-string.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ will be equivalent to
7070
qq{A ${ \scalar(TEXT) } B};
7171
```
7272

73+
The `qt` operator recognises the same escape sequences as `qq` that represent
74+
other literal characters (such as `\n` for newline or `\x00` for a NUL byte).
75+
76+
```perl
77+
print qt{This message ends in a newline\n};
78+
79+
print qt{As does this message\x0d\x0a};
80+
81+
print qt{It's Christmas! \N{SNOWMAN} };
82+
```
83+
84+
The `$` and `@` symbols are *not* considered special and will act literally,
85+
as they behave inside a `q` string.
86+
87+
```perl
88+
print qt{This apple will cost you $1.\n};
89+
# will print a literal '$' symbol followed by the digit 1, it does not
90+
# interpolate the contents of the first regexp capture buffer
91+
```
92+
93+
Likewise, the escape sequences `\L`, `\l`, `\U`, `\u`, `\Q` and `\E`, which in
94+
`qq` strings control the way that variables are interpolated, are also not
95+
considered special here. It would be helpful to users to at least issue a
96+
warning in this case, to remind them of this fact.
97+
98+
```
99+
$ perl -E 'say qt{This does not uppercase the variable \U{ $var }};'
100+
Unrecognised escape \U passed through at FILE line LINE.
101+
```
102+
73103
To provide a heredoc version of qt, this:
74104

75105
```

0 commit comments

Comments
 (0)