Re: Is there a bash/shlex-like processor with double-quotes handling?

2017-07-14 Thread Mark Carter



On 14/07/2017 15:23, Lucas Buchala wrote:

Alternatively, the «...» builtin operator already does some kind of
word splitting respecting quotes, if that fits your needs:



Thanks. I take it you are referring to the "hyper" operator (?) It looks 
good, but it doesn't quite work:

 my $d = "hello \"there world\"";
my @f = << $d >>;
 @f[1] ; # "there


As it happens, I did manage to create a grammar that respects quoting, 
and even escaped quoting:


grammar Shlex {
token TOP {<.ws>? (|)* <.ws>?}
token ws { \s+ }
rule word { <[a..zA..Z0..9\\-]>+ }
token ascii_char { <-["\\]> } # anything not a " or \
token escaped_char { "\\\"" } # literal \"
token qstring { '"' [|]* '"' <.ws>?  }
}

my $m = Shlex.parse(Q[goodbye "\"cruel\" world"  ]);
say "First  component:$m[0][0].Str()"; # OUTPUT: First  component:goodbye
say "Second component:$m[0][1].Str()"; # OUTPUT: Second component:"\"cruel\" 
world"


Re: Is there a bash/shlex-like processor with double-quotes handling?

2017-07-14 Thread Elizabeth Mattijsen
zef install Text::CSV

This is a native port of Perl 5’s Text::CSV by the original author.

> On 14 Jul 2017, at 11:12, Philip Hazelden  wrote:
> 
> If you haven't yet, you might want to look into a CSV parser. I think that if 
> you configure one of those to split on whitespace, that should give you the 
> results you want.
> 
> (Now with added reply all.)
> 
> On Fri, 14 Jul 2017, 08:42 Mark Carter,  wrote:
> Is there a function that can decompose a string to an array separated by
> whitespace, but also respecting double quotes, and prefereably escape
> sequences?
> 
> So, for example:
> 
> my $d="hello   \"cruel world\"";
> 
> something-something($d) ; => ("hello", "cruel world")


Re: Is there a bash/shlex-like processor with double-quotes handling?

2017-07-14 Thread Philip Hazelden
If you haven't yet, you might want to look into a CSV parser. I think that
if you configure one of those to split on whitespace, that should give you
the results you want.

(Now with added reply all.)

On Fri, 14 Jul 2017, 08:42 Mark Carter,  wrote:

> Is there a function that can decompose a string to an array separated by
> whitespace, but also respecting double quotes, and prefereably escape
> sequences?
>
> So, for example:
>
> my $d="hello   \"cruel world\"";
>
> something-something($d) ; => ("hello", "cruel world")
>


Is there a bash/shlex-like processor with double-quotes handling?

2017-07-14 Thread Mark Carter
Is there a function that can decompose a string to an array separated by 
whitespace, but also respecting double quotes, and prefereably escape 
sequences?


So, for example:

my $d="hello   \"cruel world\"";

something-something($d) ; => ("hello", "cruel world")