Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Text::CSV_XS function does not accept headers and key together

by Tux (Canon)
on Jun 07, 2017 at 09:15 UTC ( [id://1192255]=note: print w/replies, xml ) Need Help??


in reply to Text::CSV_XS function does not accept headers and key together

Nice case, but sory to say, the error is in your code. The key attribute expects a single scalar, not a list:

#!/usr/bin/perl use strict; use warnings; use Text::CSV_XS qw( csv ); my $file = "/home/me/Documents/www/files/data/Miscellany/Magic_items.t +xt"; open my $fh, "<", $file or die "Can't open $file $!"; my $list = csv ( in => $file, sep_char => '|', headers => [ "item", 'seen in" ], key => "item", # SCALAR, not LIST ); use Data::Dumper; print Dumper $list;

Should work exactly as you intend

I'll see if I can make a warning/error for this case


Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-03-28 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found