http://qs321.pair.com?node_id=216232

mt2k has asked for the wisdom of the Perl Monks concerning the following question:

I am continually working on a set of modules for a system I am planning to use in the (hopefully) near future. I have come across something new that I have never given much thought to. This is not a problem I have come across, but more of a question of style and perhaps preference. In these modules, I have several subroutines that give a hash as a return value. My question to you wise and wonderful monks is whether I should return a hash or a hash reference.

To explain perfectly well, this is an example of one of my subroutines:

package Module::Name; # require CGI, strict, constructor, all other code... # A sub to return a [hash|hash reference] of CGI params. sub get_params { my $self = shift; my %input; $input{$_} = $self->{$cgi_handle}->param($_) foreach $self->{$cgi_handle}->param()); # The two possible ways of returning the hash. # Is there a preference (style or personal) # as to which one I should use? return %input; # return hash # OR return \%input; # return hash reference }

The first method of returning the hash (return %input;), would be handled as such:

my $CGI = new Module::Name; my %INPUT = $CGI->get_params(); print $INPUT{'node'};

The second method of returning the has (return \%input;), would be handled as such:

my $CGI = new Module::Name; my $INPUT = $CGI->get_params(); print $INPUT->{'node'};
My guess is that this is probably a completely personal preference rather than style, but I might be wrong. If it is personal preference, I'd like to know which method other perl users prefer and perhaps any reason(s) as to why. :)