Hello iamnewbie, and welcome to the Monastery!
It looks as though your data is in CSV (comma separated values) format, in which case the best approach is to use a dedicated CSV module. For example:
#! perl use strict; use warnings; use Text::CSV_XS; my $testb = "hello,'world, yo',matt"; my $csv = Text::CSV_XS->new({ keep_meta_info => 1, quote_char => "' +" }); my @records; if ($csv->parse($testb)) { my @fields = $csv->fields; for my $col (0 .. $#fields) { if ($csv->is_quoted($col)) { push @records, $csv->{quote_char} . $fields[$col] . $csv->{quote_char}; } else { push @records, $fields[$col]; } } } else { warn "parse() failed on argument: ", $csv->error_input, "\n"; $csv->error_diag; } print "$_\n\n" for @records;
Output:
16:47 >perl 1156_SoPW.pl hello 'world, yo' matt 16:47 >
(Code adapted from the documentation for Text::CSV_XS.)
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: How to use split() in perl to ignore white space and ','
by Athanasius
in thread How to use split() in perl to ignore white space and ','
by iamnewbie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |