in reply to Re^2: Half-serious quest for prefix anonymous refs taking
in thread Half-serious quest for prefix anonymous refs taking
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Half-serious quest for prefix anonymous refs taking
by blazar (Canon) on May 30, 2008 at 19:12 UTC | |
by TGI (Parson) on May 30, 2008 at 21:42 UTC | |
by blazar (Canon) on May 31, 2008 at 09:17 UTC |