in reply to Double your return!!!!

You don't say why you'd want to do this?

In most cases              sub x{ ....; return 1 if $ok; return; }

could be replaced by        sub x{ ...; $ok;}

And I think I would code    do_it() or try_again( "...") or return;

as                        do_it() or return unless try_again("...");

You could also do           return unless do_it() or try_again("...");

I'm vascillating between those as to which is the clearer?


Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Replies are listed 'Best First'.
Re^2: Double your return!!!!
by Aristotle (Chancellor) on Feb 19, 2003 at 06:55 UTC
    could be replaced by sub x{ ...; $ok;}
    Almost. sub x { ...; !!$ok } As far as clarity is concerned, I think do_it() or return unless try_again("..."); is a clear winner.

    Makeshifts last the longest.

      !!$ok; is better, though I did say "In most cases". The only situation I can think of where

      return $ok; instead of

      return 1 if $ok; is going to fail, is if the calling code is using the boolean return value to do math?

      Can you think of any others.


      Examine what is said, not who speaks.

      The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

        It also normalizes undefined values to the false empty string, so that the calling code needn't guard against warnings. I'm not sure if context makes any difference here; I have this feeling it does, but a few very quick tests didn't confirm it.

        Makeshifts last the longest.