Re: Quote protection finally clicks

[email protected] (ToddAndMargo via perl6-users) Fri, 31 Oct 2025 22:05:14 -0700
Newsgroups perl.perl6.users
Message-ID <[email protected]>
On 10/31/25 8:49 PM, Sean McAfee wrote:
> I wrote a short Raku script that connects to my VPN provider using a 
> command piactl.  In my first version I used an approach similar to one 
> I've used many times before, calling out to a shell and being very 
> careful about shell escaping issues:
> 
> run 'bash', '-c', 'piactl disconnect && piactl set region "$1" && piactl 
> connect', '--', $region;
> 
> I happened to browse the Raku docs about quoting constructs, and 
> something finally clicked about quote protection within « » quotes.  It 
> works like a shell!
> 
> run «bash -c 'piactl disconnect && piactl set region "$1" && piactl 
> connect' -- "$region"»;
> 
> It's just as safe as the first version, but a bit more readable.
> 
> At this point I realized that I really didn't need the shell after all. 
> run in sink context raises an error, so I could just as well do that at 
> every step as for the overall chain of calls:
> 
> run <piactl disconnect>;
> run «piactl set region "$region"»;
> run <piactl connect>;
> 
> And the quote protection I was so happy to have figured out is slightly 
> less readable than the plain vanilla alternative:
> 
> run <piactl set region>, $region;
> 
> I'm glad it's there in case I need it in the future, though.  I'd use it 
> if there were additional arguments, eg:
> 
> run «piactl set region "$region" --force»;
> 
> 

Hi Sean,

Whenever I see a problem with test and quotes, I use
     Q[...]
And the concatenate it to the string.


For example:
     my Str $x = [<meta content="The Raku® programming language." 
name="description" />];

     print $x ~ "\n";

HTH,
-T