Solved

hash

Posted on 2006-10-31
4
423 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
  • 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now