Formatted printing in Perl using printf and sprintf
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.
examples/printf.pl
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>
Published on 2019-04-20
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post