in reply to The Comma Operator
(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.)perl -lwe'$oldtime = $^T; print( -(($oldtime+0) - ($oldtime = time)) ) while sleep 1'
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;perl -e'$\=$,=$";$b=1; print $b, $a += $b += $a while $a <1000; print"\n"'
|
---|