Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Embedded Newlines or Converting One-Liner to Loop

by Cristoforo (Curate)
on Dec 15, 2016 at 00:58 UTC ( [id://1177815]=note: print w/replies, xml ) Need Help??


in reply to Embedded Newlines or Converting One-Liner to Loop

Text::CSV can handle embedded newlines.
  • Comment on Re: Embedded Newlines or Converting One-Liner to Loop

Replies are listed 'Best First'.
Re^2: Embedded Newlines or Converting One-Liner to Loop
by mwb613 (Beadle) on Dec 15, 2016 at 01:17 UTC

    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!

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1177815]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-19 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found