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



In reply to Re: Subroutine Prototyping/Subroutine Argument Parsing by BrowserUk
in thread Subroutine Prototyping/Subroutine Argument Parsing by Missing Words

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.