in reply to looking for a good idiom: return this if this is true
I want a subroutine to call another subroutine, and if the return value from that subroutine is true, this subroutine should return that value, otherwise continue.
I'd think that keeping value retrieval and flow of control separate will be easiest on whoever picks up the code next. That speaks for either of your last two solutions, or something more explicit, like
my $v = thatroutine(); return $v if $v;
Since you're willing to consider taking on the overhead of eval, I rather suspect a temporary variable won't faze you, especially since it offers a convenient debug point for anyone who is stepping through the code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: looking for a good idiom: return this if this is true
by merlyn (Sage) on Mar 05, 2005 at 19:37 UTC | |
by dws (Chancellor) on Mar 06, 2005 at 00:47 UTC | |
|
Re^2: looking for a good idiom: return this if this is true
by wolfger (Deacon) on Mar 07, 2005 at 14:46 UTC | |
by merlyn (Sage) on Mar 07, 2005 at 15:18 UTC | |
by wolfger (Deacon) on Mar 07, 2005 at 17:54 UTC | |
by merlyn (Sage) on Mar 07, 2005 at 19:25 UTC |