T, Disclaimer: P6 newbie/P5 intermediate -YMMV
Regex that looks (1) quoted strings (2) any non-space-chars: / [ '"' <-[ " ]> * '"' | \S+ ] Smartmatch globally when comparing with $x $x ~~ m:global Since regex matches return Match object, they need their match string coerced out with '~'. ~( ); Mark -----Original Message----- From: ToddAndMargo [mailto:toddandma...@zoho.com] Sent: Sunday, July 16, 2017 8:26 PM To: perl6-users <perl6-us...@perl.org> Subject: Re: String to array problem > -----Original Message----- > From: ToddAndMargo [mailto:toddandma...@zoho.com] > Sent: Sunday, July 16, 2017 7:41 PM > To: perl6-users <perl6-us...@perl.org> > Subject: String to array problem > > Hi All, > > I have been scratching my head trying to figure out how to turn a string with > quotes in it into an array. > > my $x='ls -al "Program Files" "Moe Curly Larry"'; > > Desired result: > my @y; > $y[0] = 'ls'; > $y[1] = '-la'; > $y[2] = 'Program Files'; > $y[3] = 'Moe Curly Larry'; > > Any words of wisdom? > > Many thanks, > -T > On 07/16/2017 05:16 PM, Mark Devine wrote: > T, > > my $x = 'ls -al "Program Files" "Moe Curly Larry"'; > ~($x ~~ m:global/ [ > '"' <-[ " ]> * '"' | \S+ ] /); > > Mark Devine > Thank you! May I impose on you to take apart the example and explain what each part is doing? -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Computers are like air conditioners. They malfunction when you open windows ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~