Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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\" ]

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


    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?
[stevieb]: well, what happens is the Arduino 'listens' for requests r/w, and does the appropriate thing when it's interrupted based on the 'register' address sent in. It's ugly as it was my first attempt, but I've got great new ideas I'm just sitting.
[stevieb]: ...down to implement now. Here's the sketch as it currently sits
[shmem]: well I use I2C and SPI and stuff, but creating a pseudo chip looks to me like lot of indirection and memory clutter... not?
[choroba]: Are you going to use the device soon? Related to your comment about "not having much time to do a lot of coding"...
[stevieb]: sure, but I'm just learning ;) I consider it practice to get a good understanding of what goes on *after* an I2C/SPI request is made
[shmem]: ah ok. Gonna read that. but now....
shmem compiles himself into his template
[stevieb]: this is my RPi:: distribution overall automation build system physical layout. It doesn't encompass all of my RPi dists yet, ...
[stevieb]: ...but I'm getting close. I've been soldering my own PCBs to gain that experience as well, before I have my own manufactured.
[stevieb]: heh, nice *template* ;) 'night shmem!

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2017-06-25 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (572 votes). Check out past polls.