Re: String to array problem

2017-07-17 Thread Brandon Allbery
And this is another reason for the Grammar solution: it lets you do just
what is needed, in a constrained environment so you don't have any risk
(unless you do something questionable in the Grammar, but then that's on
you.)

On Mon, Jul 17, 2017 at 6:15 AM, Brent Laabs  wrote:

> Just to make it clear, do not use EVAL() ever on untrusted user input.  In
> the example I wrote, if the string contained a '>', anything after that
> point would be executed.  While it works, it's a bad idea to use it.
>
> On Mon, Jul 17, 2017 at 2:17 AM, ToddAndMargo 
> wrote:
>
>> On Sun, Jul 16, 2017 at 11:34 PM, ToddAndMargo > wrote:

 On 07/16/2017 07:48 PM, Brent Laabs wrote:

 $ perl6
> my $x='ls -al "Program Files" "Moe Curly Larry"';
 ls -al "Program Files" "Moe Curly Larry"
> ( "qww<$x>" ).perl
 ("ls", "-al", "Program Files", "Moe Curly Larry")

 How about this?  Obligatory: Much EVAL, very danger wow.


 I don't understand.  Would you put this into a full executable
 example?



>> On 07/17/2017 02:08 AM, Brent Laabs wrote:
>>
>>> I would put it in an executable example, and I already did.  But here's
>>> another one, if you like.
>>>
>>> $ perl6 -e 'my $x = q; my @y =
>>> ( "qww<$x>"); for @y.kv -> $i, $j { say "  \@y[$i] = \c39$j\c39" }'
>>>@y[0] = 'ls'
>>>@y[1] = '-al'
>>>@y[2] = 'Program Files'
>>>@y[3] = 'Moe Curly Larry'
>>>
>>> The last loop is just so it's printed in the way you demonstrated in the
>>> first post.
>>>
>>> The main point of me writing that example in the first place is because
>>> I know that the Perl 6 language itself is very good at parsing quotes.  If
>>> you knew what the string was at compile time, you could just write this:
>>>   my @y = qww;
>>> And it would know exactly how to deal with the quotes.  But I don't know
>>> how to access this functionality of the quote language from within the Perl
>>> 6 language.  You can't use qqww directly, because the quote protection is
>>> handled before interpolation, and we want it to happen after.  So I can
>>> eval a qww string instead, and that does work, though it does recognize
>>> kinds of quoting that you wouldn't expect, like dumb quotes or halfwidth
>>> katakana quotes.
>>>
>>> All of this is to say that I wish the Str.words method had a way of
>>> applying Perl 6 quoting rules as if it were the qww operator.
>>>
>>>
>> Thank you!
>>
>>
>> --
>> ~~
>> Computers are like air conditioners.
>> They malfunction when you open windows
>> ~~
>>
>
>


-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: String to array problem

2017-07-17 Thread Brent Laabs
Just to make it clear, do not use EVAL() ever on untrusted user input.  In
the example I wrote, if the string contained a '>', anything after that
point would be executed.  While it works, it's a bad idea to use it.

On Mon, Jul 17, 2017 at 2:17 AM, ToddAndMargo  wrote:

> On Sun, Jul 16, 2017 at 11:34 PM, ToddAndMargo >> > wrote:
>>>
>>> On 07/16/2017 07:48 PM, Brent Laabs wrote:
>>>
>>> $ perl6
>>>> my $x='ls -al "Program Files" "Moe Curly Larry"';
>>> ls -al "Program Files" "Moe Curly Larry"
>>>> ( "qww<$x>" ).perl
>>> ("ls", "-al", "Program Files", "Moe Curly Larry")
>>>
>>> How about this?  Obligatory: Much EVAL, very danger wow.
>>>
>>>
>>> I don't understand.  Would you put this into a full executable
>>> example?
>>>
>>>
>>>
> On 07/17/2017 02:08 AM, Brent Laabs wrote:
>
>> I would put it in an executable example, and I already did.  But here's
>> another one, if you like.
>>
>> $ perl6 -e 'my $x = q; my @y =
>> ( "qww<$x>"); for @y.kv -> $i, $j { say "  \@y[$i] = \c39$j\c39" }'
>>@y[0] = 'ls'
>>@y[1] = '-al'
>>@y[2] = 'Program Files'
>>@y[3] = 'Moe Curly Larry'
>>
>> The last loop is just so it's printed in the way you demonstrated in the
>> first post.
>>
>> The main point of me writing that example in the first place is because I
>> know that the Perl 6 language itself is very good at parsing quotes.  If
>> you knew what the string was at compile time, you could just write this:
>>   my @y = qww;
>> And it would know exactly how to deal with the quotes.  But I don't know
>> how to access this functionality of the quote language from within the Perl
>> 6 language.  You can't use qqww directly, because the quote protection is
>> handled before interpolation, and we want it to happen after.  So I can
>> eval a qww string instead, and that does work, though it does recognize
>> kinds of quoting that you wouldn't expect, like dumb quotes or halfwidth
>> katakana quotes.
>>
>> All of this is to say that I wish the Str.words method had a way of
>> applying Perl 6 quoting rules as if it were the qww operator.
>>
>>
> Thank you!
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


Re: String to array problem

2017-07-17 Thread ToddAndMargo
On Sun, Jul 16, 2017 at 11:34 PM, ToddAndMargo > wrote:


On 07/16/2017 07:48 PM, Brent Laabs wrote:

$ perl6
   > my $x='ls -al "Program Files" "Moe Curly Larry"';
ls -al "Program Files" "Moe Curly Larry"
   > ( "qww<$x>" ).perl
("ls", "-al", "Program Files", "Moe Curly Larry")

How about this?  Obligatory: Much EVAL, very danger wow.


I don't understand.  Would you put this into a full executable example?




On 07/17/2017 02:08 AM, Brent Laabs wrote:
I would put it in an executable example, and I already did.  But here's 
another one, if you like.


$ perl6 -e 'my $x = q; my @y = 
( "qww<$x>"); for @y.kv -> $i, $j { say "  \@y[$i] = \c39$j\c39" }'

   @y[0] = 'ls'
   @y[1] = '-al'
   @y[2] = 'Program Files'
   @y[3] = 'Moe Curly Larry'

The last loop is just so it's printed in the way you demonstrated in the 
first post.


The main point of me writing that example in the first place is because 
I know that the Perl 6 language itself is very good at parsing quotes.  
If you knew what the string was at compile time, you could just write this:

  my @y = qww;
And it would know exactly how to deal with the quotes.  But I don't know 
how to access this functionality of the quote language from within the 
Perl 6 language.  You can't use qqww directly, because the quote 
protection is handled before interpolation, and we want it to happen 
after.  So I can eval a qww string instead, and that does work, though 
it does recognize kinds of quoting that you wouldn't expect, like dumb 
quotes or halfwidth katakana quotes.


All of this is to say that I wish the Str.words method had a way of 
applying Perl 6 quoting rules as if it were the qww operator.




Thank you!

--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: String to array problem

2017-07-17 Thread Elizabeth Mattijsen
> On 17 Jul 2017, at 11:08, Brent Laabs  wrote:
> All of this is to say that I wish the Str.words method had a way of applying 
> Perl 6 quoting rules as if it were the qww operator.

Wouldn’t that be either .split or .comb?


Liz

RE: String to array problem

2017-07-16 Thread Mark Devine
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-users@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-users@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
~~


RE: String to array problem

2017-07-16 Thread Mark Devine
T,

This regex seems to work in both cases: m:global/ [ \\? '"' <-[ " ]> * \\? '"' 
| \S+ ] /;

#!/usr/bin/env perl6
use v6;

my ($x, @y);

$x = 'ls -al "Program Files" "Moe Curly Larry"';
@y = $x ~~ m:global/ [ \\? '"' <-[ " ]> * \\? '"' | \S+ ] /;
for @y -> $match { say ~$match; }

$x = 'ls -al \"Program Files\" \"Moe Curly Larry\"';
@y = $x ~~ m:global/ [ \\? '"' <-[ " ]> * \\? '"' | \S+ ] /;
for @y -> $match { say ~$match; }

Mark

-Original Message-
From: ToddAndMargo [mailto:toddandma...@zoho.com] 
Sent: Sunday, July 16, 2017 8:35 PM
To: perl6-users <perl6-users@perl.org>
Subject: Re: String to array problem

On 07/16/2017 05:16 PM, Mark Devine wrote:
> T,
> 
> my $x = 'ls -al "Program Files" "Moe Curly Larry"'; my @y = ~($x ~~ 
> m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /);
> 
> Mark Devine
> 
> -Original Message-
> From: ToddAndMargo [mailto:toddandma...@zoho.com]
> Sent: Sunday, July 16, 2017 7:41 PM
> To: perl6-users <perl6-users@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
> 


It kinda, sorta doesn't work:


$ cat ./QuoteArrayTest.pl6
#! /usr/bin/env perl6

use strict;

print "\n";
my $x = 'ls -al \"Program Files\" \"Moe Curly Larry\"'; my @y =~($x ~~ 
m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /); say "$x\n\@y:";

for @y.kv -> $index, $value { say "\$y[$index] = <$value>"; } print "\n"; 


ls -al \"Program Files\" \"Moe Curly Larry\"
@y:
$y[0] = 


What did I do wrong?


--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: String to array problem

2017-07-16 Thread ToddAndMargo

On 07/16/2017 06:01 PM, Brandon Allbery wrote:

Once again: http://www.mail-archive.com/perl6-users@perl.org/msg03986.html

It includes a Grammar that supports arbitrarily nested quotes, which 
can't be done in a plain regex: you could maybe handle one level, but 
not nesting.


I understand now.

I was only after one level.

Thank you!

-T


Re: String to array problem

2017-07-16 Thread ToddAndMargo

On 07/16/2017 05:57 PM, Brandon Allbery wrote:
Nested quotes and escapes are handled by the Grammar-based solution I 
pointed to. You can't handle them in general with a simple regex.


Creating a new grammer?


Re: String to array problem

2017-07-16 Thread Brandon Allbery
Nested quotes and escapes are handled by the Grammar-based solution I
pointed to. You can't handle them in general with a simple regex.

On Sun, Jul 16, 2017 at 8:54 PM, ToddAndMargo <toddandma...@zoho.com> wrote:

>
> -Original Message-
>> From: ToddAndMargo [mailto:toddandma...@zoho.com]
>> Sent: Sunday, July 16, 2017 8:35 PM
>> To: perl6-users <perl6-users@perl.org>
>> Subject: Re: String to array problem
>>
>> On 07/16/2017 05:16 PM, Mark Devine wrote:
>>
>>> T,
>>>
>>> my $x = 'ls -al "Program Files" "Moe Curly Larry"'; my @y = ~($x ~~
>>> m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /);
>>>
>>> Mark Devine
>>>
>>> -Original Message-
>>> From: ToddAndMargo [mailto:toddandma...@zoho.com]
>>> Sent: Sunday, July 16, 2017 7:41 PM
>>> To: perl6-users <perl6-users@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
>>>
>>>
>>
>> It kinda, sorta doesn't work:
>>
>> 
>> $ cat ./QuoteArrayTest.pl6
>> #! /usr/bin/env perl6
>>
>> use strict;
>>
>> print "\n";
>> my $x = 'ls -al \"Program Files\" \"Moe Curly Larry\"'; my @y =~($x ~~
>> m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /); say "$x\n\@y:";
>>
>> for @y.kv -> $index, $value { say "\$y[$index] = <$value>"; } print "\n";
>> 
>>
>> ls -al \"Program Files\" \"Moe Curly Larry\"
>> @y:
>> $y[0] = 
>>
>>
>> What did I do wrong?
>>
>
>
> On 07/16/2017 05:50 PM, Mark Devine wrote:
> > T,
> >
> > Sorry (newbie, remember).  For the first question that did not have
> backslash double-quotes:
> >
> > my ($x, @y);
> > $x = 'ls -al "Program Files" "Moe Curly Larry"';
> > @y = $x ~~ m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /;
> > for @y -> $match { say ~$match; }
> >
> > Don't know about the second question with backslash double-quotes.
> >
> > Mark
>
>
> That worked.  Thank you!
>
> 
> #! /usr/bin/env perl6
>
> use strict;
>
> print "\n";
> my $x = 'ls -al "Program Files" "Moe Curly Larry"';
> my @y = $x ~~ m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /;
> say "$x\n\@y:";
>
> for @y.kv -> $index, $value { say "\$y[$index] = <$value>"; }
> print "\n";
> 
>
>
> $./QuoteArrayTest.pl6
>
> ls -al "Program Files" "Moe Curly Larry"
> @y:
> $y[0] = 
> $y[1] = <-al>
>
> $y[2] = <"Program Files">
> $y[3] = <"Moe Curly Larry">
>



-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: String to array problem

2017-07-16 Thread ToddAndMargo

-Original Message-
From: ToddAndMargo [mailto:toddandma...@zoho.com]
Sent: Sunday, July 16, 2017 8:35 PM
To: perl6-users <perl6-users@perl.org>
Subject: Re: String to array problem

On 07/16/2017 05:16 PM, Mark Devine wrote:

T,

my $x = 'ls -al "Program Files" "Moe Curly Larry"'; my @y = ~($x ~~
m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /);

Mark Devine

-Original Message-
From: ToddAndMargo [mailto:toddandma...@zoho.com]
Sent: Sunday, July 16, 2017 7:41 PM
To: perl6-users <perl6-users@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




It kinda, sorta doesn't work:


$ cat ./QuoteArrayTest.pl6
#! /usr/bin/env perl6

use strict;

print "\n";
my $x = 'ls -al \"Program Files\" \"Moe Curly Larry\"'; my @y =~($x ~~ m:global/ [ '"' <-[ " 
]> * '"' | \S+ ] /); say "$x\n\@y:";

for @y.kv -> $index, $value { say "\$y[$index] = <$value>"; } print "\n"; 


ls -al \"Program Files\" \"Moe Curly Larry\"
@y:
$y[0] = 


What did I do wrong?



On 07/16/2017 05:53 PM, Mark Devine wrote:
> T,
>
> This regex seems to work in both cases:	m:global/ [ \\? '"' <-[ " ]> 
* \\? '"' | \S+ ] /;

>
> #!/usr/bin/env perl6
> use v6;
>
> my ($x, @y);
>
> $x = 'ls -al "Program Files" "Moe Curly Larry"';
> @y = $x ~~ m:global/ [ \\? '"' <-[ " ]> * \\? '"' | \S+ ] /;
> for @y -> $match { say ~$match; }
>
> $x = 'ls -al \"Program Files\" \"Moe Curly Larry\"';
> @y = $x ~~ m:global/ [ \\? '"' <-[ " ]> * \\? '"' | \S+ ] /;
> for @y -> $match { say ~$match; }
>
> Mark
>


Brain teaser.  Thank you again!


Re: String to array problem

2017-07-16 Thread ToddAndMargo



-Original Message-
From: ToddAndMargo [mailto:toddandma...@zoho.com]
Sent: Sunday, July 16, 2017 8:35 PM
To: perl6-users <perl6-users@perl.org>
Subject: Re: String to array problem

On 07/16/2017 05:16 PM, Mark Devine wrote:

T,

my $x = 'ls -al "Program Files" "Moe Curly Larry"'; my @y = ~($x ~~
m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /);

Mark Devine

-Original Message-
From: ToddAndMargo [mailto:toddandma...@zoho.com]
Sent: Sunday, July 16, 2017 7:41 PM
To: perl6-users <perl6-users@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




It kinda, sorta doesn't work:


$ cat ./QuoteArrayTest.pl6
#! /usr/bin/env perl6

use strict;

print "\n";
my $x = 'ls -al \"Program Files\" \"Moe Curly Larry\"'; my @y =~($x ~~ m:global/ [ '"' <-[ " 
]> * '"' | \S+ ] /); say "$x\n\@y:";

for @y.kv -> $index, $value { say "\$y[$index] = <$value>"; } print "\n"; 


ls -al \"Program Files\" \"Moe Curly Larry\"
@y:
$y[0] = 


What did I do wrong?



On 07/16/2017 05:50 PM, Mark Devine wrote:
> T,
>
> Sorry (newbie, remember).  For the first question that did not have 
backslash double-quotes:

>
> my ($x, @y);
> $x = 'ls -al "Program Files" "Moe Curly Larry"';
> @y = $x ~~ m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /;
> for @y -> $match { say ~$match; }
>
> Don't know about the second question with backslash double-quotes.
>
> Mark


That worked.  Thank you!


#! /usr/bin/env perl6

use strict;

print "\n";
my $x = 'ls -al "Program Files" "Moe Curly Larry"';
my @y = $x ~~ m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /;
say "$x\n\@y:";

for @y.kv -> $index, $value { say "\$y[$index] = <$value>"; }
print "\n";



$./QuoteArrayTest.pl6

ls -al "Program Files" "Moe Curly Larry"
@y:
$y[0] = 
$y[1] = <-al>
$y[2] = <"Program Files">
$y[3] = <"Moe Curly Larry">


Re: String to array problem

2017-07-16 Thread ToddAndMargo

On 07/16/2017 05:16 PM, Mark Devine wrote:

T,

my $x = 'ls -al "Program Files" "Moe Curly Larry"';
my @y = ~($x ~~ m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /);

Mark Devine

-Original Message-
From: ToddAndMargo [mailto:toddandma...@zoho.com]
Sent: Sunday, July 16, 2017 7:41 PM
To: perl6-users <perl6-users@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




It kinda, sorta doesn't work:


$ cat ./QuoteArrayTest.pl6
#! /usr/bin/env perl6

use strict;

print "\n";
my $x = 'ls -al \"Program Files\" \"Moe Curly Larry\"';
my @y =~($x ~~ m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /);
say "$x\n\@y:";

for @y.kv -> $index, $value { say "\$y[$index] = <$value>"; }
print "\n";


ls -al \"Program Files\" \"Moe Curly Larry\"
@y:
$y[0] = 


What did I do wrong?


--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


RE: String to array problem

2017-07-16 Thread Mark Devine
T,

my $x = 'ls -al "Program Files" "Moe Curly Larry"';
my @y = ~($x ~~ m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /);

Mark Devine

-Original Message-
From: ToddAndMargo [mailto:toddandma...@zoho.com] 
Sent: Sunday, July 16, 2017 7:41 PM
To: perl6-users <perl6-users@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


Re: String to array problem

2017-07-16 Thread ToddAndMargo



-Original Message-
From: ToddAndMargo [mailto:toddandma...@zoho.com]
Sent: Sunday, July 16, 2017 7:41 PM
To: perl6-users <perl6-users@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"';
> my @y = ~($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
~~


Re: String to array problem

2017-07-16 Thread Brandon Allbery
On Sun, Jul 16, 2017 at 7:41 PM, ToddAndMargo  wrote:

> 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';
>

This was just discussed a few days ago, under the subject "Is there a
bash/shlex-like processor with double-quotes handling?"

http://www.mail-archive.com/perl6-users@perl.org/msg03986.html

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


String to array problem

2017-07-16 Thread ToddAndMargo

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