in reply to Not quite a simple split
But it doesn't work right. 0's and 2's end up in the output. It's crappy.@parts = split m{ " # if we match a quote (?{ ++$x }) # increment quote counter (?!) # and fail | \s+ # or if we match whitespace (?(?{$x&1}) # if $x is odd (?!) # fail ) # (otherwise succeed) }x, q{A B "C D" E F"G H" I};
I'd use a regex, not split().
@parts = $string =~ m{ (?=\S) # so long as there's something ahead of us: [^\s"]* # non-quotes non-whitespace (?: " [^"]* " # a quoted part [^\s"]* # non-quotes non-whitespace )* # zero or more times }xg;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Not quite a simple split
by John M. Dlugosz (Monsignor) on Feb 02, 2004 at 03:23 UTC | |
by japhy (Canon) on Feb 02, 2004 at 14:15 UTC | |
by John M. Dlugosz (Monsignor) on Feb 02, 2004 at 16:25 UTC | |
by japhy (Canon) on Feb 02, 2004 at 19:16 UTC | |
by Roy Johnson (Monsignor) on Feb 02, 2004 at 19:52 UTC |