Link to home
Start Free TrialLog in
Avatar of perlperl
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
}
Avatar of perlperl
perlperl

ASKER

i tried this it did not work

sub display
{
   my $this         = shift;
   foreach $k (keys %{$this->{HASHARG}} )
   {
      print "$k :::::: $this->{HASHARG}{$k} \n";
   }

}
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
ASKER CERTIFIED SOLUTION
Avatar of rivusglobal
rivusglobal
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
actually the problem is solved..i was not calling the method properly

$obj->{TEST}->display()


i am havinf multiple inheritance...