Link to home
Start Free TrialLog in
Avatar of rgbcof
rgbcof

asked on

perl, using parse_line to delimit by comma, but keep the double-quotes

I use parse_line to split a string based on comma (I don't have CSV library and do not want to install it), but I want to keep the double quote.  

use Text::ParseWords;

my $mystring = "one, two, \"three\", four";
my $delim_char = ",";
my $delim_string = "\\s*$delim_char\\s*";
my @fields = &parse_line($delim_char,0,$mystring);
print join("\n",@fields),"\n";
Avatar of jeromee
jeromee
Flag of United States of America image

Please take a look at :
http://perldoc.perl.org/perlfaq4.html#How-can-I-split-a-[character]-delimited-string-except-when-inside-[character]%3f


Good luck!
ASKER CERTIFIED SOLUTION
Avatar of ropenner
ropenner
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
one
 two
 "three"
 four


This is the output if you put the '1' in the code as explained above.  Have a good one.
Avatar of rgbcof
rgbcof

ASKER

Right on.  Thanks