I am mulling over a best practice for passing hash references for return data to/from functions.
On the one hand, it seems intuitive to pass only input values to a function and have only return output variables. However, passing hashes in Perl can only be done by reference, so it is a bit messy and would seem more of an opportunity to make a mistake.
The other way is to pass a reference in the input variables, but then it has to be dealt with in the function, and it may not be clear what is an input and what is a return variable.
What is a best practice regarding this?
Return references to an array and a hash, and then dereference it.
($ref_array,$ref_hash) = $this->getData('input');
@array = @{$ref_array};
%hash = %{$ref_hash};
Pass in references (@array, %hash) to the function that will hold the output data.
$this->getData('input', \@array, \%hash);
Just return the reference. There is no need to dereference the whole
hash like you are doing in your examples:
etc.
I have never seen anyone pass in empty references to hold the result. This is Perl, not C.