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

Re: Can a single key have different value assigned to it

by Tux (Monsignor)
on Apr 19, 2012 at 09:31 UTC ( #965897=note: print w/ replies, xml ) Need Help??


in reply to Can a single key have different value assigned to it

As an alternative, use Text::CSV or Text::CSV_XS and read the whole file in one go:

use Text::CSV_XS; open my $fh, "<", $file or die "$file: $!"; my $csv = Text::CSV_XS->new ({ auto_diag => 1, binary => 1, sep_char = +> "|" }); $csv->column_names (qw( lastname firstname country language )); my $info = $csv->getline_hr_all ($fh);

With your data looking like

Wall|Larry|USA|English Walker|Johnny|Scotland|Scottish

$info (an arrayref: a pointer to a list of hashes) would look like:

[ { country => 'USA', firstname => 'Larry', language => 'English', lastname => 'Wall' }, { country => 'Scotland', firstname => 'Johnny', language => 'Scottish', lastname => 'Walker' } ]

Enjoy, Have FUN! H.Merijn


Comment on Re: Can a single key have different value assigned to it
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-08-31 02:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls