in reply to Re: hash of hashes
in thread hash of hashes

Why on earth would you want to do that?
You'd want to do that in perl if the original input contains duplicates and you only want to show unique license plate numbers. Since perl doesn't have a built-in concept of a (uniqe) set hashes are the natural structure to use.

To the OP: note that i use sort here, but that's just because I presume you'd want the output to be predictable.

$plates{$lets}{$number} =1; # or $plates{$lets}{$number}++ if you wan +t to count # and for my $let (sort keys %plates) { print "$let ",join(", ",sort keys %{$plates{$let}}),"\n"; }
Updated: removed map() - code should now be correct

Replies are listed 'Best First'.
Re^3: hash of hashes
by volcan (Novice) on Mar 23, 2007 at 22:08 UTC
    Hi Joost,

    You are correct that I am using a hash of hashes because of duplicates. The program will be reading multiple files, many of which will contain the same license plate.

    I'm going to try your code now and will report back shortly.

    Many thanks! 8^}
Re^3: hash of hashes
by Anno (Deacon) on Mar 24, 2007 at 08:05 UTC
    Well, the OP said

    proper output would look like:

    ABC 123, 334, 442 FTE 442 HHR 443 NTR 554, 554

    Note the last line, which shows a duplicate number.

    I have seen the OPs reply that confirms that duplicates are indeed unwanted. The sample output seemed to indicate the opposite.

    Anno

      Putting a duplicate in there was a mistake, so you were quite right in thinking a hash of a hash would be a bad idea since it looked like duplicates were allowed. Thanks for your help.