Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: split string by comma

by ww (Archbishop)
on Jan 11, 2012 at 01:16 UTC ( #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
Node Status?
node history
Node Type: note [id://947270]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2020-10-25 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?