by kbenson · 6y ago · 0 comments
Non interpolating quotes:
q/I wasn't surprised when he said "boo" and game me $5/;
q@I wasn't surprised when he said "boo" and game me $5@;
q!I wasn't surprised when he said "boo" and game me $5!;
q(I wasn't surprised when he said "boo" and game me $5);
q[I wasn't surprised when he said "boo" and game me $5];
Interpolating quotes: qq/Hello, $name!/;
qq!Hello, $name\!!;
qq@Hello, $name!@;
qq(Hello, $name!);
qq[Hello, $name!];
qq'Hello, $name!';
Rule of thumb, single q for single quote string (non-interpolating normally), and two q's for a double quote string (normally interpolates). s/replace #/with $/
s#replace /#with _# R"/(I wasn't surprised when he said "boo" and game me $5)/"
R"@(I wasn't surprised when he said "boo" and game me $5)@"
R"|(I wasn't surprised when he said "boo" and game me $5)|"
https://en.cppreference.com/w/cpp/language/string_literal Q/I got $5 \sigh / # literal
Q:s/Hello $name/ # just scalars
Q:b/hello world\n/ # just backslash escape sequences
https://docs.raku.org/syntax/QBecause editor tooling is important to me, I'm willing to see an ugly "\"quoted\" string" from time to time, if it means that I get better tools as a result.
Rust does too, to some degree: https://github.com/rust-lang/rust/pull/9674
$ ruby -e 'a=5; puts "[#{a}]"'
[5]
$ ruby -e 'a=5; puts %q/[#{a}]/'
[#{a}] $ ruby -e 'a=5; puts %Q/[#{a}]/'
[5]
$ ruby -e 'a=5; puts %/[#{a}]/'
[5]%q@is@
%q!strongly!
%q(inspired)
%q[by]
%q<perl>
%Q~#{"interpolating quotes"}~
%&non interpolating by default&
And qw too:
# ['this', 'is', 'a', 'list']
qw/this is a list/; ['but', 'boy', 'am', 'I', 'glad', 'I', 'don\'t', 'have', 'to', 'read', 'stuff', 'like', 'that']
qw/but boy am I glad I don’t have to read stuff like that/
But why? split("but boy am I glad I don't have to read stuff like that")
But I guess you saved three bytes, so that's nice.Suppose you have an executable "queue".
you'd generally run it as
./queue
With this rule, wouldn't that be parsed as ./q'e'e
?Finding a reserved character (or even sequence) that doesn't have collisions or unintended behavior beyond what the semi-reserved ' and " can do will be hard (but not necessarily impossible :)! ).
@"
For help, type "get-help"
"@
https://docs.microsoft.com/en-us/powershell/module/microsoft...SILLY_VAR="
My silly username is "$USER"
"
echo ${SILLY_VAR}