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' } ]
In reply to Re: Can a single key have different value assigned to it
by Tux
in thread Can a single key have different value assigned to it
by mangrove
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |