XP is just a number | |
PerlMonks |
Re: The Comma Operatorby petral (Curate) |
on Jul 20, 2001 at 11:48 UTC ( [id://98347]=note: print w/replies, xml ) | Need Help?? |
I once worked out this convoluted way to access time only once per reading without using a temporary. (Not to be obscure: the normal way to do this is something like:my $tm = time; print $tm - $oldtm; $oldtm = $tm; The only complicating factor being that you don't want to call time() twice since it may roll over in between.  In order to avoid using a temporary, the old value of oldtime must be put into the calculation before oldtime is set to its new value which must also be used. A substraction requires that its arguments be ordered, and sub-expressions for both parts seems to work.) But note well, the docs often note that the order of evaluation of arguments to functions is not defined. (This is a long-time caveat carried over from c.) For instance, the above can easily be broken:( -(($oldtime || $^T) - ($oldtime = time)) ) returns a stream of -0's! Udpate: And here's a fibonacci series that depends on $b being returned *before* it is updated. Update the second: Note also, that any halfway ambitious optimizer could reduce -( (x + 0) - (x = y) ) to (x = y) - (x) to x - x to 0 and produce:print 0;   p
In Section
Seekers of Perl Wisdom
|
|