in reply to split on spaces, except those within quotes?
#!/usr/bin/perl -w use strict; my $string = "a 'b c d' e f 'g h'"; my $tmp=''; my @result = (); for (split /\s+/, $string) { if (/^'/) { $tmp = $_; next; } elsif (/'$/) { push @result, $tmp." $_"; $tmp=''; next; } elsif($tmp) { $tmp.=" $_"; } else { push @result,$_; } } print join "\n", @result;
Of course, you could use the DBD::CSV module, setting the record delimiter to 'space' and the text quantifier to 'single quote' (spelled for clarity, not for actual use :)...
But my guess is that would be slower than a purpose designed parser for this very specific case.
.02
cLive ;-)
|
|---|