Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by JavaFan (Canon)
on Apr 19, 2012 at 09:04 UTC ( [id://965891]=note: print w/replies, xml ) Need Help??


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

So how do I assign value so that each time it is different value get assigned to the same key.
You'd use a second index. For instance:
my $count; while (my $line = <IN>) { chomp $line; my($lastname, $firstname, $country, $language) = split(/\|/, $line +); $info{lastname}[$count] = $lastname; $info{firstname}[$count] = $firstname; $info{country}[$count] = $country; $info{language}[$count] = $language; $count++; }
Or, (untested), do it all at once, and benefit fully from using strict:
my $LASTNAME = 0; my $FIRSTNAME = $LASTNAME + 1; my $COUNTRY = $FIRSTNAME + 1; my $LANGUAGE = $COUNTRY + 1; my @info = map {[/[^|\n]*/g]} <IN>;
Note that this reverses the role of the indices compared to my first suggestion -- and stores the row level data in arrays instead of hashes.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-23 11:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found