William wrote:
>
> John W. Krahn wrote:
>>
>> $ perl -le'
>> for my $num ( 123, 123456 ) {
>>      print 100000000 + $num;
>>      }
>> '
>> 100000123
>> 100123456
> 
> 
> Thank you, but I think this solution is more descent
>
> Bob McConnell wrote:
>>
>> Just insert the literal digit in the format and trim the size
>> accordingly.
>>
>> sprintf("1%08d", $number);

Maybe you do. But I suspect the intention of the analyst was that numbers should
be formatted as John describes. Bob's comment that the format 'trims the size'
is wrong. Look:

  printf "%02d", 1_000_000;

output

  1000000

Now while you may be certain that your value will never sensibly exceed
99,999,999 you would be well advised to take notice of Microsoft's assurance
that Windows XP applications will never need more than 2GB of addressable 
memory.

I suggest that John's

  print 100000000 + $num;

allows an extra decade of space over Bob's

  printf '1%08d', $number;

Both will exceed the nine-digit field width at some point, but I believe that
the first will cause fewer problems very much later.

Rob


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


Reply via email to