Re: Variable division, assignment and sprintf in one line

2007-11-29 Thread Jenda Krynicky
From: Steve Bertrand <[EMAIL PROTECTED]> > >> $var = sprintf ("%.2f", (($var /=1024) /=1024))) > > > > What the ...?!? > > > > /= ? > > It was an off the top of my head example of what I wanted to do. Without > being at the code at the time, I was simply thinking +=. If you want to divide somet

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Steve Bertrand
> $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. Oh, and furthermore,

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Steve Bertrand
>> $var = sprintf ("%.2f", (($var /=1024) /=1024))) > > What the ...?!? > > /= ? It was an off the top of my head example of what I wanted to do. Without being at the code at the time, I was simply thinking +=. > You divide the value of $var by 1024, assign it back to $var, divide > it by anot

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Jenda Krynicky
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 divi

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Steve Bertrand
Gunnar Hjalmarsson wrote: > Steve Bertrand wrote: >> 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))) > > You can write a function. > > convert( $var );

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Gunnar Hjalmarsson
Steve Bertrand wrote: 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))) You can write a function. convert( $var ); sub convert { $_[0] = sprintf '%.2f', $

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Aaron Priven
On Nov 28, 2007, at 11:26 AM, Steve Bertrand wrote: 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= ? I don't think you can do it directly, but you can use the aliasing properties of sub or for: $a_really_long_

Variable division, assignment and sprintf in one line

2007-11-28 Thread Steve Bertrand
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))) I've got a hash of hashrefs of hashrefs and I'd rather not specify the variable name on the left and r