Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: split string by comma

by ww (Archbishop)
on Jan 11, 2012 at 01:16 UTC ( [id://947270]=note: print w/replies, xml ) Need Help??


in reply to split string by comma

TIMTOWTDI, albeit, a less than entirely satisfactory way, requiring another step beyond what's here:

#!/usr/bin/perl use Modern::Perl; use Data::Dumper; # 947251 my $string = '1945,"4,399.00",938,1/10/2012'; my @string = split /(,".*?(?=")?")/, $string; print Dumper @string; =head output $VAR1 = '1945'; $VAR2 = ',"4,399.00"'; # note the leading commas retained and must be + reprocessed $VAR3 = ',938,1/10/2012'; # see =cut

See the examples in split beginning at "If the PATTERN contains parentheses, additional list elements ...."

Replies are listed 'Best First'.
Re^2: split string by comma
by RohanGuddad (Initiate) on Apr 17, 2018 at 07:54 UTC
    how to avoid the leading comma generated as per your output.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://947270]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-28 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found