Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: prototypes: so many \@'s?

by ferreira (Chaplain)
on Apr 03, 2007 at 18:01 UTC ( [id://608121]=note: print w/replies, xml ) Need Help??


in reply to prototypes: so many \@'s?

Even if you are aware, maybe it is good to remember: "Don't use prototypes". Except in a very small number of cases of restricted utility (like ($$) prototyped functions used with sort), they don't do what you want (unless you're very weirdo to match the craziness of Perl prototype semantics).

One example:

sub foo ($$) { $_[0] + $_[1] } # add two scalar args :) foo(1,2) @a = (1,2); foo(@a); # death !! not enough arguments @b1 = (2); @b2 = (3); foo(@b1,@b2) # 2 !?!? = scalar @b1 + scalar @b2

And don't take my words. Tom Christiansen said that a long time ago and Damian Conway said more about it in "Perl Best Practices".

That said, maybe you may get the behavior you want with a module like Params::Validate. See the docs with a special attention to the section on "Callback Validation":

Replies are listed 'Best First'.
Re^2: prototypes: so many \@'s?
by BrowserUk (Patriarch) on Apr 03, 2007 at 21:07 UTC

    This particular form of prototype provides a facility that cannot be achieved any other way. Perhaps you should understand what that facility is before handing out old and well worn advice those who already know it.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-24 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found