Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: prototypes: so many \@'s?

by ferreira (Chaplain)
on Apr 03, 2007 at 18:01 UTC ( #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 (Pope) 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?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2020-02-21 03:49 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (93 votes). Check out past polls.