in reply to Re: Using $_ as a temp var, especially in functions
in thread Using $_ as a temp var, especially in functions
Localizing the default pattern-matching space ($_) can make subroutines that perform several pattern-matching or other string operations against the same variable a lot quicker to write and easier to read and maintain.
I'd rather write:
local $_ = shift;
return unless length;
my $x = shift;
$x =~ s/\A[ \t]+//;
$x =~ s/[ \t]+\z//;
$x =~ tr/a-zA-Z0-9//cd;
return unless length $x;
Am I being lazy? Yeah, that's part of it, but it's exactly that sort of idiom (if that even qualifies as idiomatic) that I expect to see in Perl code.