John W. Krahn wrote:

> David wrote:
>>
>> brain dead approach:
>> 
>> #!/usr/bin/perl -w
>> use strict;
>> 
>> for(qw~ 0.203E-2    0.203E+9 0.203e-9
>>         0.20233E-12 0.123e+3 3435E+15 ~){
>> 
>>         /(\d+)E(.)(\d+)/i;
>>         my $l = $2 eq '+' ? 0 : length($1) + $3;
> 
> You shouldn't use the numerical scalars unless the match was successful.
> 
>           /(\d+)E(.)(\d+)/i and my $l = $2 eq '+' ? 0 : length($1) + $3;

it won't fail for the numbers i have for this test but yes, error checking 
is generally almost always a good thing.

> 
> 
>>         printf('%20s'. '%.' . $l . "f\n","$_ becomes ",$_);
> 
> That could also be written as:
> 
>           printf "%20s%.*f\n", "$_ becomes ", $l, $_;

yes, whichever you prefer.

> 
> 
>> }
> 
> Or, you could write it like this:
> 
> for ( qw(0.203E-2 0.203E+9 0.203e-9 0.20233E-12 0.123e+3 3435E+15) ) {
>     ( my $l = sprintf "%.18f", $_ ) =~ s/\.?0+$//;
>     printf "%12s becomes %s\n", $_, $l;
>     }

no. try it with 0.20233e-20.

david
-- 
$_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$";
map{~$_&1&&{$,<<=1,[EMAIL PROTECTED]||3])=>~}}0..s~.~~g-1;*_=*#,

goto=>print+eval

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to