I want to print all the lines sorted by the Town. Like this
Town 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.