Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

hash

Posted on 2006-10-31
4
Medium Priority
?
435 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 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

670 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