Literals & quoting

String literals & quoting

Full

Single vs double quotes, the q/qq family, and heredocs.

Raku has a rich set of quoting constructs. The two you reach for most are single quotes (literal) and double quotes (interpolating); the q/qq forms generalise them with choosable delimiters and adverbs.

Single vs double quotes #

Single quotes are literal — only \\ and \' are special. Double quotes interpolate scalar variables and { } code blocks.

my $n = 42;
say 'cost $n';
say "cost $n";
Output
cost $n
cost 42

The q and qq forms #

q// is single-quote semantics, qq// is double-quote semantics — but you choose the delimiter, so quotes inside the text need no escaping. Bracketing delimiters nest.

say q{a{b}c};
say qq[one and one is {1 + 1}];
Output
a{b}c
one and one is 2
Pick a delimiter that isn't { } when you want { } interpolation inside a qq string — with brace delimiters the inner block is ambiguous with the delimiter.

Heredocs #

qq:to/END/ starts a heredoc: the text runs until a line containing the terminator. Leading indentation is stripped to match the terminator's, so the source stays tidy.

my $name = "Ada";
say qq:to/END/.trim;
  Dear $name,
  Welcome.
  END
Output
Dear Ada,
Welcome.

Notes #