From:                   Steve Bertrand <[EMAIL PROTECTED]>
> Hi again all,
> 
> Is there a way that one can use sprintf on a variable and assign the
> value back to the variable without having the leading $var= ?
> 
> $var = sprintf ("%.2f", (($var /=1024) /=1024)))

What the ...?!?

/= ?

You divide the value of $var by 1024, assign it back to $var, divide 
it by another 1024, assign it again to $var, then format the 
resulting number using sprinf() and assign it to $var?!? Why???

$var = sprintf ("%.2f", (($var / 1024) / 1024));

will do the same as will

$var = sprintf ("%.2f", $var / (1024*1024));

And it will be more efficient because the multiplication will be done 
at compile time (once) and you'll only do a single division each 
time. Which is also more precise, though in this case it doesn't seem 
to matter.

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to