I want to print all the lines sorted by the Town. Like thisTown Surname Firstname Basel Chaplin Charlie Manica Estevez Emilio Santa Montmarte Sarte Jean Paul Montmarte Rodin Paul Amsterdam Rikard Frank
This doesn't look sorted alphabetically, and in any other way, just with the columns in a different order.
Maybe Text::Table can help you a bit.
As for your second question, please use strict; use warnings; - the warnings tell you where it first went wrong.
my @elems = $key; my $client = $client->[$elems[1]-1];
This produces the warnings Use of uninitialized value $elems[1] in subtraction (-) at foo.pl line 25.
That's because you assign one item to the array @elems, and then access the second item (with index 1), which is always undef.
Somehow I can't make any sense of what you try to do in here.
if ($a =~ /[Basel Manica Montmarte Amsterdam]/) {
You've clearly never tested that with an invalid town name. You should. And then read perlre on what the square brackets mean in regular expressions.
From a more high-level perspective I think your problem is that you write too much code that relies on the variables you filled earlier, without looking if the variables contain what you think they do.
A great tool for debugging is Data::Dumper, which will produce Perl code that reflects your data structure, for example:
use Data::Dumper; my @a = (2, 5, 7); print Dumper \@a;
produces
$VAR1 = [ 2, 5, 7 ];
Use that to check if your variables contain what you think they should.
In reply to Re: An REAL array of hashes
by moritz
in thread An REAL array of hashes
by fseng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |