Bob Showalter wrote:
> Jamie Risk wrote:
> > How would I split, then push onto a list a variable length text
> > string with quoted portions (example following) so that a split
> > keeps text in quotes together. 
> > 
> >   "keep me together" separate1 separate2 separate3 "keep me
> > together too" separate4 
> > 
> > If the above were parsed, I should like to see six separate
> > elements. Using 'split' with no parameters understandably gives me
> > eleven elements.
> 
> You really can't do this with split(). Use the Text::CSV_XS module
> from CPAN instead.
> 
> <http://search.cpan.org/author/JWIED/Text-CSV_XS/>

Just for kicks, here's a way to do it using split(). Text::CSV_XS is still
recommended, as it can deal with unbalanced quotes, escaped embedded quotes,
etc.

$ perl -le 'print for map { /"(.*)"/ ? $1 : split " ", $_ } split /(".*?")/,
q["keep me together" separate1 separate2 separate3 "keep me together too"
separate4]'

Output:
keep me together
separate1
separate2
separate3
keep me together too
separate4


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

Reply via email to