Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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.

Input:
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
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').


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2014-12-22 19:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (126 votes), past polls