in reply to passing array of args to prototyped subs

This might be a dumb question, but why do you need to use function prototypes to start with? If you are concerned about having correct argument types/numbers being passed in I'd just do some basic param checking in the function itself and catch it at runtime, which is probably where you want to have some sanity checks anyway.

  • Comment on Re: passing array of args to prototyped subs

Replies are listed 'Best First'.
Re^2: passing array of args to prototyped subs
by pldanutz (Acolyte) on Sep 10, 2013 at 05:38 UTC

    Because writing out the code to check arguments is longer and less convenient than writing f ($$), I guess?

    Yes, I realize it's only a few extra characters, I realize that this example is trivial (since I SIMPLIFY code before posting it), and I realize that the community doesn't seem to like prototypes (possibly for very good reasons)
      I realize that the community doesn't seem to like prototypes

      Well — not exactly. The Perl community is fine with prototypes when they’re used appropriately. The problem is, most of us come to Perl with a background in C/C++/Java, see Perl prototypes, and think, “That must be Perl’s way of doing argument checking.” But prototypes have little to do with argument checking; they are all about argument coercion.

      This is explained in detail in the classic article Far More than Everything You've Ever Wanted to Know about Prototypes in Perl -- by Tom Christiansen (written by the co-author of the Camel Book, no less). That article is a must-read for every Perl programmer.

      Hope that helps,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        Thanks a lot. That article *really* helped.

      I realize that the community doesn't seem to like prototypes.

      You probably referring, inter alia, to my comment of yesterday to another of your posts. Just to make things clear, I did not tell you not to use prototypes, I told you not to use prototype unless you really know how to do it and, more importantly, why you are doing it (and I might have added, unless you really know what they are doing). I personally use them only extremely rarely, but there have been few cases where I have found them handy.