sstruthe has asked for the wisdom of the Perl Monks concerning the following question:
Hi my code below which is sanatised and might not work here runs fine reading a file with $1 $2, ie two elements first one is key and second is value into a hash. But now I want to have more than one value I would like $1{key} $2,$3,$4 so I assume hash of arrays.
my $input_file = "dat.txt"; our %dedicated; open(DATA, "<$input_file" ) or die; while ( my $line = <DATA> ) { chomp $line; my ($a, $b) = split ' ', $line; $dedicated{$a} = $b; } keys %dedicated; while (my ($k, $v) = each %dedicated ) { chomp($k, $v); blah } } }
How do I change from reading in and using a hash, to a hash of arrays on a file like. names1 john,bob,stu names2 mike,john,bob names3 blah. ...... Many thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: read a file and build HoA
by Athanasius (Archbishop) on Dec 10, 2015 at 12:19 UTC | |
|
Re: read a file and build HoA
by Discipulus (Canon) on Dec 10, 2015 at 12:20 UTC | |
|
Re: read a file and build HoA
by sstruthe (Novice) on Dec 10, 2015 at 14:02 UTC |