Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: trouble with text::csv

by Tux (Canon)
on Dec 05, 2021 at 09:55 UTC ( [id://11139402]=note: print w/replies, xml ) Need Help??


in reply to Re: trouble with text::csv
in thread trouble with text::csv

*almost* correct: the return values for $csv->header is a list, not a scalar:

my $csv = Text::CSV_XS->new; # Or Text::CSV my @hdr = $csv->header ($if, { detect_bom => 1 }); # No need for $csv->column_names, as that is implicit in ->header

Personally I'd go for the easiest solution, where all of that is integrated:

use Text::CSV_XS qw( csv ); my $aoh = csv (in => $dbfile, sep => "\t", bom => 1);

If you need the order of the header later, you can keep that too:

my $aoh = csv (in => $dbfile, sep => "\t", bom => 1, kh => \my @hdr);

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^3: trouble with text::csv
by tangent (Parson) on Dec 05, 2021 at 14:16 UTC
    Thanks for the insights (and for the excellent software). I did dump the $header in my example and got a Text::CSV object, so didn't try the list assignment.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2024-04-16 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found