benlaw has asked for the wisdom of the Perl Monks concerning the following question:
1. i try to pass a string "problem1" to a class, but it result "packa=HASH(0x1b0effc)" when I pass the value to the class, what i am not expected.
2. I have a array inside a hash, mm when i pass the array back into main.pl, how to get value?$string = $obj->pass("problem1");
full code hereif ($key eq "problem2"){ foreach (@ha{$key}){ print "array : @{$_}\n";
#in main.pl use packa; $obj = packa->new; $string = $obj->pass("problem1"); #print $string; %ha = $obj -> passhash; foreach $key (keys (%ha)){ if ($key eq "problem2"){ foreach (@ha{$key}){ print "array : @{$_}\n"; } } } #in packa.pm package packa; sub new{ my $class = shift; my $self = {}; bless($self); return $self; } sub pass{ my ( $problem1 )= @_; print "$problem1\n"; } sub passhash{ %hash = qw { dog voa cat mice }; $hash {'problem2'} = [["ha" , "thing", "thorw"], ["good", "ssa" , "ham"], ["as", "kid", "wo"], ]; return %hash; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: two problems about passing var between classes
by Biker (Priest) on Apr 11, 2002 at 15:16 UTC | |
|
Re: two problems about passing var between classes
by perlplexer (Hermit) on Apr 11, 2002 at 15:20 UTC | |
|
Re: two problems about passing var between classes
by Ovid (Cardinal) on Apr 11, 2002 at 16:03 UTC | |
|
Re: two problems about passing var between classes
by Hofmator (Curate) on Apr 12, 2002 at 11:13 UTC | |
|
Re: two problems about passing var between classes
by benlaw (Scribe) on Apr 12, 2002 at 01:58 UTC |