This seems to work:
----Code-----------------------------
#!/usr/local/bin/perl
my $str= "a bc \"d e f\" h \"i j\"";
print "str==$str==\n";
my $m= "_##_"; #Marker
$str =~ s,\"(\S),\"$m$1,g;
print "str==$str==\n";
@toks= map { (/^$m/)? do{ s,$m,,; $_ } : split(/\s+/, $_) } (split(/\"/,
$str));
print "tokens::", join(":", @toks), "::\n";
----Code-----------------------------
----Output-----------------------------
str==a bc "d e f" h "i j"==
str==a bc "_##_d e f" h "_##_i j"==
tokens::a:bc:d e f::h:i j::
----Output-----------------------------
-Nilanjan
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Donald Leslie {74279}
Sent: Tuesday, October 04, 2005 12:28 PM
To: [email protected]
Subject: [Boston.pm] splitting a string containing quoted fields
I have a string of the form:
'a bc "d e f" h "i j"' what I want is the quoted items not
to split on blanks.
[0] = 'a' , [1] = 'bc' , [2] = 'd e f' ... .
Is there is simple way to do this ?
Don Leslie
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm