in reply to subroutines - passing hashes by reference

In addition to what perlplexer said, try moving your return outside the foreach loop :-)

What happened? I thought I wrote this right after perlplexer posted his reply. /me shrugs.

  • Comment on Re: subroutines - passing hashes by reference

Replies are listed 'Best First'.
Re: Re: subroutines - passing hashes by reference
by Anonymous Monk on May 01, 2003 at 15:20 UTC
    many many thanks - moved the return and its perfect!
      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.