Ashok,
There are a couple of errors here:
1. You're using the array reference ( and thus, the entire list) as a key to your hash with a value of 'ashok'. This is backwards. I think (correct me if I misunderstood) you want to use 'ashok' as the key to the hash whose value is the array ref.
2. Change the inner for loop ( I'd use foreach instead, but that's a matter of personal preference) to refelect the changes suggested in (1).
Try this:
#! /usr/bin/local/perl use strict; use warnings; my $array_ref = [1, 2, 5, 7, 4]; my %hash; $hash{'ashok'} = $array_ref; foreach my $as ( keys %hash ) { foreach ( @{ $hash{$as} } ) { print "$_, "; } }
Hope this helps.
In reply to Re: How to dereference when hash key is referenece
by njcodewarrior
in thread How to dereference when hash key is referenece
by ashokpj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |