in reply to looking for a good idiom: return this if this is true

return $_ if $_ = thatroutine();?

I tried

return $var if my $var = thatroutine();
and
return my $var if $var = thatroutine();
but neither works.

Replies are listed 'Best First'.
Re^2: looking for a good idiom: return this if this is true
by gaal (Parson) on Mar 06, 2005 at 08:50 UTC
    Don't do that; $_ is a global.
      I concur.

      And I've previously found when I was doing a micro-optimisation effort somewhere, that $_ is also relatively slow to assign and then read from, compared to the temporary variable.