Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Is there any danger in doing something like this?
When I say 'danger', I'm wondering if I may be surprised at my result due to the order of evaluation being different than I expect.$temp = defined($temp = &func()) ? $temp : 'undefined';
By the way, my motivation for this is to either save a little space by not declaring an extra variable:
or to save a little time by not calling func twice:$temp1 = &func(); $temp2 = defined($temp1) ? $temp1 : 'undefined';
$temp = defined(&func()) ? $func() : 'undefined';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Safe to use ternary operator like this?
by ChOas (Curate) on Nov 16, 2000 at 20:13 UTC | |
by arturo (Vicar) on Nov 16, 2000 at 20:48 UTC | |
by Albannach (Monsignor) on Nov 16, 2000 at 20:43 UTC |