printf can be used to create a formatted print to the screen.

sprintf accepts the same parameters, but it will return the formatted string instead of printing it so you can collect the string and print them later, or save them to a file or send them in an e-mail.


my $v = 65;
printf("<%s>\n", $v);     # <65>
printf("<%10s>\n", $v);   # <      65>
printf("<%-10s>\n", $v);  # <65      >
printf("<%c>\n", $v);     # <A>
printf("<%d>\n", $v);     # <65>
printf("<%0.5d>\n", $v);  # <00065>