Update: As blazar so kindly pointed out, the (@) prototype is indeed meaningless. It just goes to show how useful it is to reread the docs every once in a while. I'd filed away the fact that prototypes let you do cool stuff and omit parens. Which they do, but not in the way that I understood it at the time I first read the docs.

Reread the docs from time to time. It's amazing what you can learn!

Back to my regularly scheduled foolishness...


The % and @ prototypes do the same thing--eat an entire list. Your suggestion that it should check for evenness is very good. It's in my battered old copy of Perl in a Nutshell, it works, but I don't see it in perlsub--interesting...

I used the % prototype despite its identicalness with @ just to clearly show my intentions--that is mkhref wants a hash. I'm not sure about that decision now, since it turns out to be a partially documented feature :).

The prototypes allow you to skip your parentheses, which makes the sub act more like a built-in. Since you said you wanted a built-in, I thought I'd fake it as well as can be done.

mkaref( 1..9 ); # becomes mkaref 1..9;

In a module, I'd have mkhref check for warnings, with $^W. If on, it should carp, that way the error refers to the "right" line of code.

sub mkhref (%) { if ( @_%2 ) { carp "Odd number of elements in mkhref" if $^W; return { @_, undef }; } else { return {@_}; } }


TGI says moo


In reply to Re^3: Half-serious quest for prefix anonymous refs taking by TGI
in thread Half-serious quest for prefix anonymous refs taking by blazar

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.