Surname L20, First Name L20, Town L20 -------------------------------------------------- Chaplin Charlie Basel Estevez Emilio Santa Manica Sarte Jean Paul Montmarte Rikard Frank Amsterdam Rodin Paul Montmarte #### Town Surname Firstname Basel Chaplin Charlie Manica Estevez Emilio Santa Montmarte Sarte Jean Paul Montmarte Rodin Paul Amsterdam Rikard Frank #### 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 () { 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'}"; } #Print out the surname of people live in the town print "Please enter a town name: "; my $a = ; my $town; if ($a =~ /[Basel Manica Montmarte Amsterdam]/) { my $client->{'town'} = $a; print ${$client}[$town] } else{ die "Invalid town name supplied: $a"; }