Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Can't find right printf format

Reply
Thread Tools

Can't find right printf format

 
 
Hubert Gabler
Guest
Posts: n/a
 
      04-28-2008
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
 
Reply With Quote
 
 
 
 
Steven M. O'Neill
Guest
Posts: n/a
 
      04-28-2008
Hubert Gabler <> wrote:
>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


The magic word is "padding".

http://www.google.com/search?q=printf+padding

--
Steven O'Neill
Brooklyn, NY http://www.panix.com/~steveo
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      04-28-2008

Quoth 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


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
--
The cosmos, at best, is like a rubbish heap scattered at random.
Heraclitus

 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      04-28-2008
>>>>> "HG" == Hubert Gabler <> writes:

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

--
Uri Guttman ------ -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
Hubert Gabler
Guest
Posts: n/a
 
      04-29-2008
>...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
 
Reply With Quote
 
szr
Guest
Posts: n/a
 
      04-29-2008
Hubert Gabler wrote:
> 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.)

--
szr


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
printf affects following printf/s azza C Programming 0 10-17-2010 09:43 AM
Extracting printf(...) from (void) printf(....) guru Perl Misc 8 02-03-2009 10:37 PM
Splitting a multirecord per file format to a single record per file format: Right approach? Randy Kramer Ruby 2 01-12-2007 06:46 PM
(void) printf vs printf whatluo C Programming 29 09-08-2005 05:42 PM
bus error with printf line included, error without printf line? ben C Programming 4 06-26-2004 04:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57