Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

How DOES printf() work?

by petdance (Parson)
on Jun 22, 2001 at 08:18 UTC ( [id://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
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-18 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found