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

thatroutine() =~ /(.+)/s and return $1;
Obviously, whether or not this technique will work depends on the kinds of values the function returns.

Replies are listed 'Best First'.
Re^2: looking for a good idiom: return this if this is true
by cosimo (Hermit) on Mar 08, 2005 at 07:33 UTC

    Sorry, no offense, but this looks really terrible to me... Why on earth do you want to fire up a regex matching here?

    Probably this has also an interesting side effect: it could convert a "numeric" scalar into a "string" scalar. No good.

      I'm not saying it's good, but it does answer the OP, somewhat, and it's very short.
      ...it could convert a "numeric" scalar into a "string" scalar. No good.
      If you think such conversions are inherently bad, then Perl probably isn't the language for you.