in reply to Splitting a line on just commas
Output:use strict; sub main{ my $text = qq{a,b,"hey, you","str1, str2, str3",end}; print "Input: $text\n\n"; # Split the delimiters my @values = split( /(?:\,|(\".*?\"))/ , $text); # Remove the created blanks @values = grep{$_ ne ''} @values; # Output foreach (0..$#values){ print "$_: $values[$_] \n"; } } main();
Input: a,b,"hey, you","str1, str2, str3",end 0: a 1: b 2: "hey, you" 3: "str1, str2, str3" 4: end
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Splitting a line on just commas
by ikegami (Patriarch) on Jun 14, 2010 at 17:39 UTC | |
by deMize (Monk) on Jun 14, 2010 at 17:51 UTC | |
by ikegami (Patriarch) on Jun 14, 2010 at 18:05 UTC | |
by deMize (Monk) on Jun 14, 2010 at 18:17 UTC | |
by ikegami (Patriarch) on Jun 14, 2010 at 19:13 UTC | |
by ikegami (Patriarch) on Jun 14, 2010 at 19:15 UTC |