Re: fractional cents

"A. Pagaltzis" <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <20040419212221.GD6439@klangraum>
* Quantum Mechanic <[email protected]> [2004-04-19 23:09]:
> --- "A. Pagaltzis" <[email protected]> wrote:
> >     my $amt_str = sprintf "%7.3f", $amt;
> >     for($amt_str) { chop if /\.\d\d0\z/ } 
> 
> Why would you do "for..chop" when you could do "s///"?
> You're using an re either way?
> 
> ;)
> 
> =====
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Quantum Mechanics: The dreams stuff is made of

Because I think

    chop if /\.\d\d0\z/;

is clearer to read than

    s/(?<=\.\d\d)0\z//;

or even (yuck!)

    s/(\.\d\d)0\z/$1/;

The last one is even semantically different, even though it does
the same thing.

-- 
Regards,
Aristotle
 
"If you can't laugh at yourself, you don't take life seriously enough."
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.