Solved

hash

Posted on 2006-10-31
4
430 Views
Last Modified: 2012-05-05
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
}
0
Comment
Question by:perlperl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 

Author Comment

by:perlperl
ID: 17843238
i tried this it did not work

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

}
0
 

Author Comment

by:perlperl
ID: 17843799
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
0
 
LVL 10

Accepted Solution

by:
rivusglobal earned 500 total points
ID: 17843888
Hi perlperl,

If you are trying to debug a complex hash structure you could use Data::Dumper like this:

use Data::Dumper;

sub display {
    $this = shift;
    print Dumper( $this );
}

or you could just iterate through the key/value pairs like this:

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

Author Comment

by:perlperl
ID: 17844100
actually the problem is solved..i was not calling the method properly

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


i am havinf multiple inheritance...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question