in reply to Hash reference question

From perldoc perlsub (in the section on Prototypes):

Any backslashed prototype character represents an actual 
argument that absolutely must start with that character.
The value passed to the subroutine (as part of @_) will be 
a reference to the actual argument given in the subroutine 
call, obtained by applying \ to that argument. 

I interepret that to mean that the behaviour that you're seeing in correct. Perl expects you to pass a hash to the subroutine. Perl will then take a reference to the hash and pass that into the subroutine as the argument. You should therefore pass a hash into the subroutine, but expect a reference to a hash within the subroutine.

--
<http://www.dave.org.uk>

European Perl Conference - Sept 22/24 2000, ICA, London
<http://www.yapc.org/Europe/>

Replies are listed 'Best First'.
RE: RE: Hash reference question
by splinky (Hermit) on Jul 13, 2000 at 20:57 UTC
    davorg is, of course, correct.

    I just wanted to add my generic advice that you shouldn't use prototypes unless you get in a position where you need them. I made the same mistake as you early on, finding function prototypes in perldoc, and thinking I should use them everywhere. I have since revisited my old code and removed all the prototypes.

    They're indispensable when you need them, and a real irritant when you don't. If you don't know when you need them, then you don't need them.

    *Woof*

Thanks!
by Anonymous Monk on Jul 13, 2000 at 17:47 UTC
    Thanks! That was it. I assumed that I must tell Perl that it's a hash reference, using eg. foo(\%someHash); Indeed, it seems that Perl takes a reference from the given hash behind the scenes so to speak. Good to know though, now I can finish the documentation :)