I probably deserve hate mail for this one but...
#! perl -sw use strict; sub tokenize ($) { local $_ = shift; s/(('|").*?\2)/ ($£ = $1) =~ s!\s+!\cA!g; $£ /ge; #!" grep{s/\cA/ /g, $_}split/\s+/; } my @bits = tokenize q/a "b c d" e f 'g h' ijk "l m n " op 'q r s +t' u'v w'x yz/; local $,='|'; print @bits,$/; __END__ c:\test>212174 a|"b c d"|e|f|'g h'|ijk|"l m n "|op|'q r s t'|u'v w'x|yz|
In reply to Re: split on spaces, except those within quotes?
by BrowserUk
in thread split on spaces, except those within quotes?
by pg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |