in reply to hash of hashes
A hash of hashes is exactly appropriate to your problem. The code below counts the number of times each plate has been seen, but if vehicle information needed to be associated with plates then that could become the value rather than a count:
use strict; use warnings; my %plates; while (<DATA>) { chomp; next if ! /(\w+)\s+(\d+)/; ++$plates{$1}{$2}; } for my $group (sort keys %plates) { print "$group ", join ', ', sort {$a<=> $b} keys %{$plates{$group +}}; print "\n"; } __DATA__ ABC 334 NTR 557 ABC 442 FTE 442 HHR 443 NTR 554 ABC 123
Prints:
ABC 123, 334, 442 FTE 442 HHR 443 NTR 554, 557
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash of hashes
by volcan (Novice) on Mar 25, 2007 at 19:57 UTC |