Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: passing array of args to prototyped subs

by pldanutz (Acolyte)
on Sep 10, 2013 at 05:38 UTC ( [id://1053166]=note: print w/replies, xml ) Need Help??


in reply to Re: passing array of args to prototyped subs
in thread passing array of args to prototyped subs

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)

Replies are listed 'Best First'.
Re^3: passing array of args to prototyped subs
by Athanasius (Archbishop) on Sep 10, 2013 at 06:39 UTC
    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.

        The article also gives you the answer to your original question:

        print &f2 (@a) . "\n";

        even if you probably do not want to know it anymore...

Re^3: passing array of args to prototyped subs
by Laurent_R (Canon) on Sep 10, 2013 at 10:12 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1053166]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-29 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found