Pete Emerson wrote:
> 
> I'd appreciate it if someone could help me wrap my brain around this one.
> I've got a string like this:
> $string='"one two" three "four five six"';
> 
> I'd like to wind up with an array like this:
> one two
> three
> four five six
> 
> Essentially, I would like to split up the string on spaces, but ignore spaces that 
>are
> inside pairs of quotes. So:
> $string='"one two" three "four five" six "seven eight nine"';
> should wind up as:
> one two
> three
> four five
> six
> seven eight nine
> 

I try another approach than all the good ones I've already read:

# Regexp for quoted words
my $q = qr/"\w+(?:\s+\w+)*"/;
# Regexp for simple words
my $w = qr/\w+/;

my @parts = map {s/"//g; $_} $string =~ /\s* ($q | $w)/xg;

print join "\n", @parts;

produces your wanted output.
I hope, it's simplier to read and understand this snippet.

Best Wishes,
Andrea

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to