raku.gg
[ BACK... ]
By: w1ldc4rd-w1z4rd
Mastering Interpolation with qq
The Essence of qq
qq is Raku’s powerful string interpolation construct:
my $animal = "fox";
say qq[The quick brown $animal jumps over the lazy dog];
Flexible Delimiters
qq allows various delimiter symbols:
say qq(Parentheses);
say qq[Square Brackets];
say qq{Curly Braces};
say qq<Angle Brackets>;
say qq!Exclamation Marks!;
say qq/Slashes/;
Comprehensive Escape Sequence Table
Here’s a detailed table of escape sequences in qq, including their hex values:
| Sequence | Hex Value | Character |
|----------|-----------|----------------|
| \0 | \x0000 | Null |
| \a | \x0007 | Alert (Bell) |
| \b | \x0008 | Backspace |
| \e | \x001B | Escape |
| \f | \x000C | Form Feed |
| \n | \x000A | Newline |
| \r | \x000D | Carriage Return|
| \t | \x0009 | Tab |
Practical Usage of Escapes
say qq:to/END/;
Null: \0 (hex: \x0000)
Bell: \a (hex: \x0007)
Backspace: \b (hex: \x0008)
Escape: \e (hex: \x001B)
Form feed: \f (hex: \x000C)
Newline: \n (hex: \x000A)
Carriage return: \r (hex: \x000D)
Tab: \t (hex: \x0009)
END
Additional Important Escapes
say qq[
Backslash: \\
Dollar sign: \$
Double quote: \"
Unicode by codepoint: \x[1F600]
Unicode by name: \c[SMILING FACE]
];
Combining Interpolation and Escapes
my $name = "Alice";
my @hobbies = <coding hiking>;
say qq:to/END/;
Profile for $name:
Hobbies: @hobbies[]
Favorite number: { (1..100).pick }
Escaped dollar: \$100
Special chars: \t\n\a
Unicode: \x[1F680] (hex: 1F680)
END
Key Takeaways
- qq offers flexible delimiters for string creation
- It supports a wide range of escape sequences, each with a specific hex value
- Escapes allow for precise control over special characters and formatting
- Combine escapes with interpolation for powerful string manipulation
Remember, mastering these escapes gives you fine-grained control over your strings in Raku. Whether you’re dealing with special characters, formatting, or Unicode, qq and its escape sequences have got you covered!
WWW: 🐪 perl.gg - 🧙♂️ clc.onl - 💾 GitHub - 🏙️ Neocities
Copyright ©️ 2024 raku.gg