[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2010-08-19
4
Medium Priority
?
1,672 Views
Last Modified: 2012-05-10
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";
0
Comment
Question by:rgbcof
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Expert Comment

by:jeromee
ID: 33478926
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!
0
 
LVL 8

Accepted Solution

by:
ropenner earned 500 total points
ID: 33480020
Put a 1 for the $keep variable (2nd parameter)

man Text::ParseWords explains the syntax of the below

my @fields = &parse_line($delim_char,1,$mystring);
0
 
LVL 8

Expert Comment

by:ropenner
ID: 33480034
one
 two
 "three"
 four


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

Author Closing Comment

by:rgbcof
ID: 33480506
Right on.  Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question