|Welcome to the Monastery|
Re^2: Why doesn't Perl provide %_ as the hash equivalent of @_ in subs? (ugly++)by smls (Pilgrim)
|on Sep 27, 2013 at 09:37 UTC||Need Help??|
"Please oh please don't require people to search the entire code of your routine in order to figure out what parameters can be passed to it!"
Yes, it wouldn't make sense to use %_ in most long & complicated routines.
I never intended to suggest that it would become The One True WayTM for accessing subroutine arguments.
I just think it would be a useful additional tool in the Perl developer's toolbox, nicely complementing the existing ones (in particular @_ which it would semantically mirror very closely), to be deployed with discretion.
I myself would use %_ sparingly, just like I currently use direct access to $_ (or, similarly, $_ in foreach loops) sparingly. But sparingly does not mean "never useful"!
In the OP I've already given a use-case that can appear even in big Perl applications, where I think %_ has its place - let me elaborate on that:
Besides @_, the use of %_ as I imagine it can be compared to the use of $_ in foreach loops.
Using $_ instead of $person in that example would entail many of the same or similar disadvantages/problems as the ones that you and other commenters have invoked against the use of %_ in subs.
And yet, Perl does make $_ available as a built-in language feature.
Perl trusts me to make an informed decision when to use $_ and when not. The fact that it can be used in ways that make code unreadable or buggy, wasn't deemed enough of a reason to exclude it from the language.
Why not apply the same principle to %_?