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:
Or, (untested), do it all at once, and benefit fully from using strict: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++; }
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.my $LASTNAME = 0; my $FIRSTNAME = $LASTNAME + 1; my $COUNTRY = $FIRSTNAME + 1; my $LANGUAGE = $COUNTRY + 1; my @info = map {[/[^|\n]*/g]} <IN>;
In reply to Re: Can a single key have different value assigned to it
by JavaFan
in thread Can a single key have different value assigned to it
by mangrove
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |