in reply to Subroutine References

I'll give you the obligatory plug to Tom Christiansen's excellent Prototypes in Perl article from perl.com. You seem to be only using prototypes to "use minimal error checking on the values passed to the subroutines" as you say (your other comments only refer to predeclaring subs). Tom's article explains well why prototypes don't really do this for you (or at least do it poorly at the cost of certain usability). Prototypes are cute sometimes to be able to pass references implicitly (a \@ prototype for instance), making your sub look more like a builtin (i.e, push)... but it looks like you understand how references work, so passing them explicitly and foregoing prototypes would probably be no skin off your back. Again, I can't explain it half as well as Tom does, so please read that article!

More on point to your original question, here's the relevant text from perldoc perlsub:

The prototype affects only interpretation of new-style calls to the function, where new-style is defined as not using the "&" character. In other words, if you call it like a built-in function, then it behaves like a built- in function. If you call it like an old-fashioned subroutine, then it behaves like an old-fashioned subroutine. It naturally falls out from this rule that prototypes have no influence on subroutine references like \&foo or on indirect subroutine calls like &{$subref} or $subref->().

blokhead

Replies are listed 'Best First'.
Re: Re: Subroutine References
by Ninthwave (Chaplain) on Dec 07, 2003 at 22:47 UTC

    I have read both but missed the reference bit because I wasn't using references at the time. Should have reread when I encountered this error. Thank you for that though. But even more importantly it gives me a reason to stop prototyping. I felt I needed to stop doing it after reading the above article but couldn't really say why until this.

    "No matter where you go, there you are." BB