http://qs321.pair.com?node_id=947270


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.