in reply to Re: How to read data file into an array of hashes
in thread How to read data file into an array of hashes
I did something like this:Town Surname Firstname Basel Chaplin Charlie Manica Estevez Emilio Santa Montmarte Sarte Jean Paul Montmarte Rodin Paul Amsterdam Rikard Frank
But this doesnt work somehow. Can anyone help please?my $data = "clients.dat"; open (DAT, $data) or die "\"$data\" not existed or can't be opened!\n" +; my @client; # make this an array, not a hash; my @fields = qw/surname firstname town/; while (<DAT>) { next if ( /^Surname/ or /^-/ ); my @values = unpack 'A20A20A20', $_; my %entry = map { $fields[$_] => $values[$_] } ( 0..$#fields ); push @client, \%entry; } my @towns; my $client; foreach my $client (@client){ push @towns, "$client->{'town'}"; } my @sorted_towns = sort @towns; foreach my $key (@sorted_towns) { my @elems = $key; my $client = $client->[$elems[1]-1]; print "$client->{'town'} $client->{'surname'} $client->{'firstname +'}"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to read data file into an array of hashes
by graff (Chancellor) on Jun 24, 2009 at 18:02 UTC | |
by fseng (Novice) on Jun 25, 2009 at 06:00 UTC | |
by fseng (Novice) on Jun 26, 2009 at 00:14 UTC |