Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Forcing list context of passed parameters

by Sidhekin (Priest)
on Sep 28, 2007 at 21:42 UTC ( #641618=note: print w/ replies, xml ) Need Help??


in reply to Forcing list context of passed parameters

A prototype is not just documentation. Don't use it if you don't mean it!

Having said that, here are two suggestions:

# honour the prototype: print foo( one => qw( two three four ) ), "\n";

Since you consider the prototype valuable as documentation, you will likely value the documentation of setting the first argument apart in the call as well.

# bypass the prototype: print &foo( qw( one two three four ) ), "\n";

While not recommended in this situation, it may be useful with arguments from other expressions, particularly function calls:

# bypass the prototype: print &foo( bar(@args) ), "\n";

But as you've been told, it is likely better to just give up this use of prototypes.

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!


Comment on Re: Forcing list context of passed parameters
Select or Download Code
Re^2: Forcing list context of passed parameters
by papidave (Monk) on Sep 28, 2007 at 22:25 UTC
    Sidhekin and others wrote:
    just give up this use of prototypes
    This would seem to be the consensus. Having suffered through years of mismatched parameters in C, and having been rescued by good parameter checking when the ANSI standard finally came out for the platforms where I was working, a habit was formed that didn't map well into this environment.

    I had a good chat with mr_mischief regarding http://perldoc.perl.org/perlsub.html#Prototypes and in particular the section referencing retrofits that explains the root cause on my list getting eaten.

    Having been soundly downvoted (ouch!), I guess I will be forced to follow more closely to the docs:

    This is all very powerful, of course, and should be used only in moderation to make the world a better place.
    and leave my lack of moderation to other vices.

      Prototypes in perl aren't parameter checking, they're hints to the compiler that you're trying to mimic the calling convention of a builtin. If you still want parameter checking look into something like Params::Validate.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-07-31 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (249 votes), past polls