Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Loading a hash table

by idsfa (Vicar)
on Jan 03, 2006 at 17:47 UTC ( [id://520675]=note: print w/replies, xml ) Need Help??


in reply to Loading a hash table

Use Text::xSV:

use Text::xSV; my $csv = Text::xSV->new( filename => "foo.csv", header => \@column_names, ); while ($csv->get_row()) { # You could use fetchrow_hash here, but I'll just print a message # If you want a HoH or AoH, read up on extract_hash my ($name, $alert_publisher) = $csv->extract(qw(Name alert_publisher +)); print "Dll: $name\t is " . (($alert_publisher eq 'X')? '' : 'not ') . "an alert publisher\n"; }

It's worth noting that your problem as posed overwrites the hash each time you read in a new line. If this is not what you want, you need to construct an array (or a hash) of hashes ... see the comment for pointers.


The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-20 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found