Hello again
Why I still believe that your question in not answered?
Although the rest of the monks they have replied to your question in a variety of ways stating more or less the same I think you are getting confused on how the parameters are passed on the subroutine. Correct if I am wrong but I think you are getting confused about the @_ in the subroutine why there is only one and not two correct?
Sample of code taken from (perlsub/Pass by Reference) with minor modifications:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my %hash_1 = (a => 26, b => 2, c => 3);
my %hash_2 = (z => 26, y => 25);
my ($ahashref, $bhashref) = func(\%hash_1, \%hash_2);
print Dumper $ahashref, $bhashref;
sub func {
my ($cref, $dref) = @_;
if (keys %$cref > keys %$dref) {
return ($cref, $dref);
} else {
return ($dref, $cref);
}
}
I use (Data::Dumper) for debugging purposes to analyze the @_. Sample of the output from the example provided above:
print Dumper \@_;
$VAR1 = [
{
'b' => 2,
'a' => 26,
'c' => 3
},
{
'y' => 25,
'z' => 26
}
];
What you see here is an perldsc/ARRAYS OF HASHES. Maybe the perlsub/DESCRIPTION will help a bit more:
Any arguments passed in show up in the array @_ . (They may also show up in lexical variables introduced by a signature; see Signatures below.) Therefore, if you called a function with two arguments, those would be stored in $_[0] and $_1 . The array @_ is a local array, but its elements are aliases for the actual scalar parameters. In particular, if an element $_[0] is updated, the corresponding argument is updated (or an error occurs if it is not updatable). If an argument is an array or hash element which did not exist when the function was called, that element is created only when (and if) it is modified or a reference to it is taken. (Some earlier versions of Perl created the element whether or not the element was assigned to.) Assigning to the whole array @_ removes that aliasing, and does not update any arguments.
If still your question is not answered let us know.
Seeking for Perl wisdom...on the process of learning...not there...yet!
|