in reply to Re: Embedded Newlines or Converting One-Liner to Loop
in thread Embedded Newlines or Converting One-Liner to Loop

Right... I'm just seeing the old thread (from 2003) now

I think I ignored it before because my log processor doesn't just work with CSVs but I think I can probably work around that.

Thanks!

  • Comment on Re^2: Embedded Newlines or Converting One-Liner to Loop

Replies are listed 'Best First'.
Re^3: Embedded Newlines or Converting One-Liner to Loop
by haukex (Archbishop) on Dec 15, 2016 at 09:14 UTC

    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