Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

How DOES printf() work?

by petdance (Parson)
on Jun 22, 2001 at 08:18 UTC( #90629=perlcraft: print w/replies, xml ) Need Help??

   1: #!/usr/bin/perl
   2: 
   3: # I can never remember the order of the meanings of
   4: # the printf() formats, so I cranked out this little
   5: # program to show me.
   6: 
   7: my @formats = qw(
   8:         %s
   9:         %10s
  10:         %-10s
  11:         %10.10s
  12:         %-10.10s
  13: 
  14:         %d
  15:         %10d
  16:         %-10d
  17:         %10.10d
  18:         %-10.10d
  19: 
  20:         %f
  21:         %10f
  22:         %-10f
  23:         %10.10f
  24:         %-10.10f
  25:         );
  26: my %values = ( s => "JLHooker", f => "12345.67", d => "1234567" );
  27: 
  28: 
  29: for my $format ( @formats ) {
  30:         my $type = substr( $format, -1 );
  31:         $format = "|$format|";
  32: 
  33:         printf( "%-10.10s     %s\n", $format, sprintf( $format, $values{$type} ) );
  34: } # for

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlcraft [id://90629]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2016-08-30 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (410 votes). Check out past polls.