Maverick
Maverick

Reputation: 587

How to pass a reference of a hash and array to subroutine

I am trying to pass a hash reference and array reference to subroutine but getting error like invalid class string:

sub test{
           if($chk == 2)
             {
                return(\%hash,\@array);
              } 
        }


my ($has, $arr)= test();

Now again i have to pass by reference to "$has, $arr" to a another subroutine.

How to do this? i was passing them like \%$has, \@$arr but it seems this is not the currect way to pass to a subroutine.

Upvotes: 0

Views: 98

Answers (2)

Gansi
Gansi

Reputation: 11

my %Hash=('1'=>'one');

my @Arr=('1','2');

&fun(\%Hash,\@Arr);

sub fun(){

my $Hash_Ref=shift;

my $Arr_Ref=shift;
enter code here
&Fun2($Hash_Ref,$Arr_Ref);

} sub fun2(){

my $Hash_Ref=shift;

my $Arr_Ref=shift; 

}

Upvotes: 0

Toto
Toto

Reputation: 91385

Just do:

anotherSub($has, $arr);

$has and $arr are already references.

Upvotes: 3

Related Questions