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;
In reply to two problems about passing var between classes by benlaw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |