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 ( #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

Comment on How DOES printf() work?
Download Code

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 cooling their heels in the Monastery: (7)
As of 2014-12-29 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (185 votes), past polls