Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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\" ]

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2018-03-25 05:40 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (300 votes). Check out past polls.