in reply to References, hashes, and tie() -- oh my

jacques,
In the first working example, a hash is passed to the sub by reference and so modifications to the underlying data structure are reflected after the sub exits. In the second broken example, the sub is creating a lexical hash reference that can't possibly affect a hash outside of its scope. The solution is to modify the module's sub to accept a hash reference.

Cheers - L~R

Incidently, my ($hash) = @_; is spelled better as my $hash = shift;

Replies are listed 'Best First'.
Re^2: References, hashes, and tie() -- oh my
by jZed (Prior) on Jun 11, 2005 at 01:13 UTC
    my ($hash) = @_; is spelled better as my $hash = shift;
    Why? With the first way, if you change your mind about the number of params you can change just the left hand side, but with your way, if you change the left hand side and forget to change the right, you'll end up with a hard to spot bug
Re^2: References, hashes, and tie() -- oh my
by devnul (Monk) on Jun 11, 2005 at 00:28 UTC
    Incidently, my ($hash) = @_; is spelled better as my $hash = shift;

    .. I couldn't disagree with this more....

    dEvNuL
      devnul,
      Not that it has anything to do with jacque's problem, but what specifically do you disagree with? That my ($hash) = @_; shouldn't be spelled differently at all, or the way I chose to spell it? The only way I can see to improve the readability would have been to say my $hash = shift @_;

      Update: Ok, after hearing several arguments in the CB along with jZed's reply, I am convinced that it is not necessarily better to write it that way. I doubt I will change how I write my code but I won't think it is deficient when others do.

      Cheers - L~R