in reply to Re^2: Hash Trouble
in thread Hash Trouble
The new code was missing the association of $val
Not at all. There's no reason to do
$val = $msg;
$analysis{$key} = $val;
when
$analysis{$key} = $msg;
suffices.
For me I would rather build one hash table instead of multiple hash tables and then merging them. To me it seems like a waste what are your thoughts?
To which multiple hashes are you refering? You mean if you if you were to keep the timestamp? You could do something like:
while(<RPT>) { chomp; if (/^(\D+.*\d{4}\s+)(\D+.*)(\w{11})$/) { my $timestamp = $1; my $msg = $2; my $key = $3; fmt_rpt($msg); if (exists($analysis{$key})) { $analysis{$key}[1] .= $msg; } else { $analysis{$key} = [ $timestamp, $msg ]; } } else { print "Program Error 2\n"; exit 1; }
See perllol for details. This would be a HoA (Hash of Arrays), which is similar to the mentioned AoA (Array of Arrays).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Hash Trouble
by tc1364 (Beadle) on Nov 19, 2004 at 18:55 UTC | |
by ikegami (Patriarch) on Nov 19, 2004 at 19:09 UTC |