http://www.perlmonks.org?node_id=1055803

TL;DR version:

I think %_ should be available inside subroutines, and contain the same parameter list as @_ but interpreted as a hash.
Why is this currently not the case?

Longer version:

For functions that needs to handle a flexible number of named arguments, one would traditionally pass a hash and then add a line at the top of the function to rebuild the hash from @_:

sub dostuff { my %arg = @_; # Access named parameters like $arg{foo} } dostuff( foo => 'FOO', bar => 1 );

If it's a long and unique function, that's fine because the syntactical overhead is negligible. However, consider cases where you have multiple small (say, one-liner) functions that are all called the same way - for example when using lambda functions as callbacks:

sub_with_callbacks ( red => sub { my %arg = @_; .. $arg{foo} .. }, green => sub { my %arg = @_; .. $arg{foo} .. }, blue => sub { my %arg = @_; .. $arg{foo} .. }, yellow => sub { my %arg = @_; .. $arg{foo} .. } );

The my %arg = @_; has now become annoying boilerplate that makes my code less sexy. I hate that.

Compared to other languages, Perl usually excels at providing little tricks and magic variables and whatnot to allow me to create cute and condensed snippets of code in cases where that is appropriate. But here, the (to my mind) obvious feature is missing: Allowing direct access to the parameter list (interpreted as a hash) via %_ - which would make it possible to replace the previous example code block with the following, much nicer one:

sub_with_callbacks ( red => sub { .. $_{foo} .. }, green => sub { .. $_{foo} .. }, blue => sub { .. $_{foo} .. }, yellow => sub { .. $_{foo} .. } );

I wonder why Perl does not provide this feature, seeing as:

I'd be interested in hearing any qw(thoughts opinions explanations background-info musings) that my fellow Monastery dwellers might have on this.