0

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.

1
  • You are "getting an error like invalid class string"? That's smacks of a Windows CLSID registration error, not a perlish error. Can we please see the code that demonstrates the problem, rather than your narrative description of what you think you need to do to solve it? Commented Aug 29, 2013 at 15:22

2 Answers 2

3

Just do:

anotherSub($has, $arr);

$has and $arr are already references.

Sign up to request clarification or add additional context in comments.

Comments

0

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; 

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.