You really shouldn't try to parse CSV data by hand. Having a quoted field with an embedded comma will quickly make your life miserable. If you create a regex which will accurately parse CSV data, then it's going to be less than pleasant to maintain. Try something like Text::CSV_XS:
use strict; use Text::CSV_XS; my $csv = Text::CSV->new; my $csv_file = 'schedulea.csv'; open CSVFILE, "< $csv_file" or die "Can't open $csv_file for reading: +$!"; while (<CSVFILE>) { my $status = $csv->parse($_); if ( $status ) { my @columns = $csv->fields(); # do stuff with columns } else { my $bad_argument = $csv->error_input(); # do stuff with the error } }
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) Re: Padding with zeroes fails
by Ovid
in thread Padding with zeroes fails
by Kickstart
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |