Hi mwb613,
I second Text::CSV as "the" solution for reading CSV files, especially if they've got things like embedded newlines. It would also help in the case that the input format changes, since Text::CSV is quite flexible.
my log processor doesn't just work with CSVs but I think I can probably work around that
One solution would be to abstract out the handling of records, so that it doesn't matter where they come from:
my $csv = Text::CSV->new({ binary => 1, eol => $/ })
or die Text::CSV->error_diag;
open my $fh, "<", $file or die "$file: $!";
while ( my $row = $csv->getline($fh) ) {
handle_row($row);
}
$csv->eof or $csv->error_diag();
close $fh;
sub handle_row {
# ...
}
(Untested, mostly a copy-n-paste from Text::CSV.)
Hope this helps, -- Hauke D |