rwitmer has asked for the wisdom of the Perl Monks concerning the following question:
Here's the code:10 a l 11 b m
The input is like this:#!/usr/bin/perl use strict; use warnings; my $filename = $ARGV[0]; my $outFilename = $ARGV[1]; open OUTFILE, ">", $outFilename or die $!; open FILE, $filename or die $!; my $id; my $date; while(<FILE>) { my $line = $_; if($_ =~ /(.*?)\t+(.*?)\[/ ) { $id = $1; $date = $2; print OUTFILE "$id\t$date\n"; } my $key; my $i; my %HoA; push @{ $HoA{$id} }, $date; my $k; foreach $k (keys %HoA) { print "$k\n\t"; foreach (@{$HoA{$k}}) { print " $_"; } print "\n"; } }
But the output is sadly like this:10 a[ 11 b[ 12 c[ 13 d[ 14 e[ 15 f[ 16 g[ 17 h[ 18 i[ 19 j[ 20 k[ 10 l[ 11 m[ 12 n[ 13 o[ 14 p[ 15 q[ 16 r[ 17 s[ 18 t[ 19 y[ 20 v[
This confuses me because it looks like it is making more than one hash entry per key. What am I doing wrong here?10 a 11 b 12 c 13 d 14 e 15 f 16 g 17 h 18 i 19 j 20 k 10 l 11 m 12 n 13 o 14 p 15 q 16 r 17 s 18 t 19 y 20 v
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash of Arrays
by wind (Priest) on Mar 09, 2011 at 21:50 UTC | |
|
Re: Hash of Arrays
by fidesachates (Monk) on Mar 09, 2011 at 22:02 UTC |