⭐ in reply to How do I pass more than one array or hash to a subroutine
You can create a reference by simply prefixing a variable with \ like so:
To use them inside of their routines you can do stuff like the following:processarrays(\@array1, \@array2); processhashes(\%hash1, \%hash2);
$sub processarrays{ my($a1, $a2) = @_; foreach(@$a1){ # dereferences $a1 print $_; } for($i=0; $i<@$a2; $i++){ print $a2->[$i]; #get at a particular index within array } } sub processhashes{ my($h1,$h2)=@_; foreach my $key(keys %$h1){ #derefences $h1; print $h1->{$key}; #lookup based on $key } }
|
|---|