Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by Tux (Abbot)
on Jun 07, 2017 at 09:15 UTC ( #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
Node Status?
node history
Node Type: note [id://1192255]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2019-06-27 02:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (111 votes). Check out past polls.

    Notices?