Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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?
[Corion]: marto: Ow, I hope that gets better soonish! But I feel some $work-timecrunch looming at my $work as well
[Corion]: marto: Ah, so you can multiplex work and PM time ;-D
[Corion]: The upside to this is that I've reduced my $work (well, $paid) time to 80%, so I'll be at $work only four days/week, which will hopefully make the crunch less crunchy on me ;)
[marto]: yeah, so that stays as before. But before the boys were born I'd be on quite often at night (GMT) also
[marto]: I had the option during our TUPE transfer to buy 5 more days holiday. They were shocked when I did :P

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2017-06-29 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (655 votes). Check out past polls.