Philip Potter wrote:
2009/9/11 Steve Bertrand <st...@ibctech.ca>:
Uri Guttman wrote:
it is actually very simple to understand. the key point to knowing it
and how to use it is that the 2 value expressions SHOULD NOT have side
effects. that means changing something by assignment or other
modification. your example below is one exception to that.
Since I use functions/methods to perform side effects frequently, I
believe what you mean is that in *most* cases, the conditional op
shouldn't ever have anything that must be evaluated in one of the
either/or fields.
For example, this:
my $num = 1;
my $add_to = 2;
my $ret = ( $foo == 1 ) ? ( $num + $add_to ) : 2;
...SHOULD _always_ ( where possible ) be written as:
my $expr_result = ( $num + $add_to );
my $ret = ( $foo == 1 ) ? $expr_result : 2;
No, that's not it. ($num + $add_to) is an expression with no
side-effects.
That expression may indeed have side effects if the + operator is
overloaded.
perldoc overload
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/