http://www.perlmonks.org?node_id=641618


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!

Replies are listed 'Best First'.
Re^2: Forcing list context of passed parameters
by papidave (Pilgrim) 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.