Can't find right printf format

H

Hubert Gabler

Hello,
my problem is very simple, but I cannot find the answer in "Learning
Perl" nor in the manpages:
Which FORMAT in printf makes the numbers 1,2,3,.. look like 001,002,003..?
Hubert
 
B

Ben Morrow

Quoth Hubert Gabler said:
Hello,
my problem is very simple, but I cannot find the answer in "Learning
Perl" nor in the manpages:
Which FORMAT in printf makes the numbers 1,2,3,.. look like 001,002,003..?
Hubert

perldoc -f printf says 'printf FILEHANDLE FORMAT, LIST' is equivalent to
'print FILEHANDLE sprintf FORMAT, LIST' (with a caveat), so you need to
look in perldoc -f sprintf. This contains a full list of the conversion
specifiers supported by Perl.

Ben
 
U

Uri Guttman

HG> my problem is very simple, but I cannot find the answer in
HG> "Learning Perl" nor in the manpages: Which FORMAT in printf makes
HG> the numbers 1,2,3,.. look like 001,002,003..? Hubert

FAQ

perldoc -q pad

uri
 
H

Hubert Gabler

...you need to look in perldoc -f sprintf.

Thanks to all who gave me this hint. I simply overlooked the link from
printf to sprintf. I promise to read the manpages more careful in the
future before asking the experts!
Kind regards,
Hubert
 
S

szr

Hubert said:
Hello,
my problem is very simple, but I cannot find the answer in "Learning
Perl" nor in the manpages:
Which FORMAT in printf makes the numbers 1,2,3,.. look like
001,002,003..? Hubert

%03d

This will give you 3 zero-padding digits (if you remove the zero from
the format, it will be the same width, but space-padded instead.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top