Home > Archive > PERL Beginners > March 2008 > create multiple hash
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
create multiple hash
|
|
| Sivasakthi 2008-03-21, 8:01 am |
| Hi all,
I want to create multiple hash and retrieve the values for print like
below ,
%values= (
'172.16.1.45' => {'google.com' => 34, 'linux.com' => 45},
'172.15.2.34' => {'hp.com' => 345, 'oracle.com' => 4567},
);
how to do that?
Thanks,
| |
| J. Peng 2008-03-21, 8:01 am |
| creating a multiple hash is the same as you create a common hash.
you can do,
my %value;
$value{'172.16.1.45'} = {'google' => 34};
$value{'172.15.2.34'} = {'yahoo' => 45};
etc.
to show the hash structure, use Data::Dumper:
use Data::Dumper;
print Dumper \%hash;
to print the hash, use a for loop:
for my $outkey (keys %hash) {
for my $inkey (keys %{$hash{$outkey}}) {
print $inkey, ": ", $hash{$outkey}->{$inkey},"\n";
}
}
Not tested it.Good luck.
Regards,
Jeff (Joy) Peng
On Fri, Mar 21, 2008 at 6:33 PM, sivasakthi <msivasakthi@gmail.com> wrote:
> Hi all,
>
> I want to create multiple hash and retrieve the values for print like
> below ,
>
> %values= (
> '172.16.1.45' => {'google.com' => 34, 'linux.com' => 45},
> '172.15.2.34' => {'hp.com' => 345, 'oracle.com' => 4567},
>
> );
>
>
> how to do that?
>
>
>
> Thanks,
>
|
|
|
|
|