in reply to Re: subroutines - passing hashes by reference
in thread subroutines - passing hashes by reference

many many thanks - moved the return and its perfect!
  • Comment on Re: Re: subroutines - passing hashes by reference

Replies are listed 'Best First'.
Re: Re: Re: subroutines - passing hashes by reference
by hmerrill (Friar) on May 02, 2003 at 13:32 UTC
    A side note - really just a personal preference of mine that might help you. Name variables what they are - if a scalar is a reference to a hash, name it as such. For example, if you pass a reference to a 'user' hash in to subroutine print_user, then do it this way:
    sub print_user { my $user_hashref = shift; print "user name = $user_hashref->{'name'}\n"; print "user age = $user_hashref->{'age'}\n"; } ### main part of code ### my %user = { "name" => "John Doe", "age" => 12 } print_user(\%user);
    That way, you always know that scalar $user_hashref is really just a *reference* to the user hash, and it needs to be treated like a reference to a hash, instead of like an actual hash.

    HTH.