Leading Zeroes 
Author Message
 Leading Zeroes

Is there any way to force leading zeroes with the format command?
I know how to do it with printf, but I think the code is more readable with
format.

Any assistance is greatly appreciated.

-Josh Sunshine



Sat, 15 May 2004 02:26:24 GMT  
 Leading Zeroes

Quote:

> Is there any way to force leading zeroes with the format command?
> I know how to do it with printf, but I think the code is more readable with
> format.

> Any assistance is greatly appreciated.

> -Josh Sunshine

If you find format easier to read, then you can use it -- you still need
to pair it with sprintf, however:

#! /usr/local/bin/perl

my $leading_zeros = sprintf("%05d",2);
my $ten_k = 10000;

format STDOUT =

$leading_zeros

$ten_k
.

write;

# VS.

printf "PRINTF:  %05d\n", 2;
printf "JUSTIFY: %5.2f\n", $ten_k;

--
Cheers,
Steve



Sat, 15 May 2004 04:55:29 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. matching leading zeros but not a single zero

2. regular expression - cutting leading zeros from a string

3. regular expression replace string to pad leading zeros

4. How to get rid of leading zeros?

5. strip leading zeros

6. Formatting to delete leading zeroes

7. stripping leading zeros thru multiple fields

8. No Leading Zero In printf

9. Adding leading zeros with regexp

10. handling numbers with leading zeros

11. get rid of these leading zeros in Perl

12. Remove leading zeros from a string

 

 
Powered by phpBB® Forum Software