I agree with you general sentiment. IMO $_ should be used to increase readability. For the most part explicit use of $_ is a detriment to readability.
For example, I will use $_ explicitly when I would otherwise be creating a throwaway variable:
foreach ( @array_of_array_refs ) { my @current_array = @$_; # do some destructive processing on @current_array } #compare to foreach my $current_array_ref ( @array_of_array_refs ) { my @current_array = @$current_array_ref; # do some destructive processing on @current_array }
I feel believe that this helps reduce visual noise, and keeps the code focused on what is important. Unpacking $_ to a scalar may be used to avoid side effects due to the aliasing of loop variables.
TGI says moo
In reply to Re: a rule of thumb for $_ in Perl
by TGI
in thread a rule of thumb for $_ in Perl
by apotheon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |