Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Split process

by santhosh_89 (Scribe)
on Aug 04, 2009 at 06:20 UTC ( #785649=perlquestion: print w/ replies, xml ) Need Help??
santhosh_89 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have a scalar variable,I need to be splited based on the comma(,).if the comma is present with in double or single quote.The split or regular expression should not consider it.

my $a="a,b,\"c,d\"";
There is a comma with in c and d.The code should not be considered that comma(,),The output should be as following. output of Dumper:
$VAR1=[ a, b, \"c,d\" ]

Comment on Split process
Select or Download Code
Replies are listed 'Best First'.
Re: Split process
by moritz (Cardinal) on Aug 04, 2009 at 06:22 UTC
    You should use a module like Text::CSV for that (and set the delimiter to the comma).
Re: Split process
by Skeeve (Vicar) on Aug 04, 2009 at 06:31 UTC

    I think, split can't handle that easily.

    If you can't (everyone can) go the suggested route of using a propper module, please bear in mind that a quote inside quotes might appear and so has to be escaped somehow.

    So you have to find out how this escaping is done. Some application double them ("this is a 24"" monitor"), some might use backslashes ('can\'t open file') or even go the "shell way" ('this ain'\''t cool').


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://785649]
Approved by Skeeve
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2015-10-05 05:00 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (107 votes), past polls