perlperl
asked on
hash
Test1.pm
sub new
{
my $proto = shift;
my $class = ref($proto) || $proto;
my $this = {
HASHARG => &_generateList() ### this function returens hash (return \%hash (format is $hash{124} = david))
};
bless $this, $class;
return $this;
}
sub _generateList {
#blahhhh
my %hash;
$hash{123} = 'john';
$hash[456} = 'adam';
return \%hash;
}
sub display{
$this = shift;
### how can i display the keys and valus of HASHARG in thsi prt of code
}
sub new
{
my $proto = shift;
my $class = ref($proto) || $proto;
my $this = {
HASHARG => &_generateList() ### this function returens hash (return \%hash (format is $hash{124} = david))
};
bless $this, $class;
return $this;
}
sub _generateList {
#blahhhh
my %hash;
$hash{123} = 'john';
$hash[456} = 'adam';
return \%hash;
}
sub display{
$this = shift;
### how can i display the keys and valus of HASHARG in thsi prt of code
}
ASKER
if i try to print in the new()
foreach $k (keys %{$this->{HASHARG}} )
{
print "$k :::::: $this->{HASHARG}{$k} \n";
}
it works fine...
but when i call $obj->display()
it does not print the vakue
foreach $k (keys %{$this->{HASHARG}} )
{
print "$k :::::: $this->{HASHARG}{$k} \n";
}
it works fine...
but when i call $obj->display()
it does not print the vakue
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
actually the problem is solved..i was not calling the method properly
$obj->{TEST}->display()
i am havinf multiple inheritance...
$obj->{TEST}->display()
i am havinf multiple inheritance...
ASKER
sub display
{
my $this = shift;
foreach $k (keys %{$this->{HASHARG}} )
{
print "$k :::::: $this->{HASHARG}{$k} \n";
}
}