in reply to Subroutine Prototyping/Subroutine Argument Parsing

A purely personal view, but I think the main problem is that you are over specifying the subroutine.

I'm also not adverse to using perl's prototypes when I feel that they benefit my code, but in this case, I don't see the benefit. If you haven't already read FMTEYEWtKaPiP, then I highly recommend it. If you still want to use a prototype for this after doing so, then I'd probably suggest a simple (;$) at most, but even that is overkill I think.

Your major problem/concern seems to be that you want to allow for multiple, omitable arguments. As I already said, I don't think this case warrents it, but you have two (probably more, but these come to mind) options, if you don't use a prototype,.

If you wish to specify the ordering of the arguments, and allow the user to supply the second argument whilst omitting the first, he can do so by using undef

eg. my $pw = masked_input undef, '#';.

The second option would be to use named parameters:

masked_input( ref => \my $pw, mask => '#' ); my $pw = masked_input( mask => '@' ); my $pw = masked_input();

Again, I think this is overkill for this application, but for some purposes, this can be a very useful way to do things.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller