sundeep has asked for the wisdom of the Perl Monks concerning the following question:
I didn't know, where exactly did go wrong. Please check my code and let me know the mistake please.
use strict; use warnings; use Data::Dumper; open (S,"<sample.data") or die $!; my @file=<S>; my %samplehash; my @fields; my ($key,$subkey); for ( my $i=0;$i<=$#file;$i++) { @fields=split /\s+/,$file[$i]; $samplehash{$fields[1]}{$fields[0]}=$fields[2]; } foreach $key (keys %samplehash) { print "\n $key = $samplehash{$key} "; foreach $subkey (keys %samplehash{$key}) { print "\n $subkey = $samplehash{$key}{$subkey} "; } } close S;
Thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Assign and print Hash of hashes
by jffry (Hermit) on Nov 22, 2010 at 06:19 UTC | |
by sundeep (Acolyte) on Nov 22, 2010 at 17:30 UTC | |
by jffry (Hermit) on Nov 23, 2010 at 16:28 UTC | |
|
Re: Assign and print Hash of hashes
by PeterPeiGuo (Hermit) on Nov 22, 2010 at 04:38 UTC | |
by sundeep (Acolyte) on Nov 28, 2010 at 15:52 UTC | |
|
Re: Assign and print Hash of hashes
by kcott (Archbishop) on Nov 22, 2010 at 06:42 UTC | |
by jwkrahn (Abbot) on Nov 22, 2010 at 08:30 UTC | |
by kcott (Archbishop) on Nov 22, 2010 at 08:51 UTC |