Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Why doesn't Perl provide %_ as the hash equivalent of @_ in subs?

by ikegami (Pope)
on Sep 26, 2013 at 14:12 UTC ( #1055840=note: print w/ replies, xml ) Need Help??


in reply to Why doesn't Perl provide %_ as the hash equivalent of @_ in subs?

It would be silly to always create a hash from the arguments.

  • Extremely expensive where it's not needed.
  • Causes warnings if you pass undef at even indexes.
  • Causes warning if you pass an odd number of arguments.
  • Useless for methods.
  • Useless for sub that have any positional parameters.

So either create it yourself (local %_ = @_; or alias local %_ = @_;) when it's acceptable, or create an attribute you can specify on a sub which does it for you (e.g. sub foo :named_args { ... }).


Comment on Re: Why doesn't Perl provide %_ as the hash equivalent of @_ in subs?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055840]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (19)
As of 2015-07-07 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls