——#!/usr/bin/perl
=begin metadata
Name: printf
Description: format and print data
Author: Tom Christiansen, tchrist@perl.com
License: perl
=end metadata
=cut
# printf - format and print data
use
strict;
END {
close
STDOUT ||
die
"$0: can't close stdout: $!\n"
;
$? = 1
if
$? == 255;
# from die
}
unless
(
@ARGV
) {
die
"usage: $0 format [argument ...]\n"
;
}
my
$format
=
shift
;
$format
=~ s/\\v/\x0b/g;
# escape \v not available in printf()
$format
=~ s/\
%c
/\%\.1s/g;
# standard printf: %c == 1st char
eval
qq(printf "$format", \@ARGV)
;
die
if
$@;
__END__
=head1 NAME
printf - format and print data
=head1 SYNOPSIS
B<printf> I<format> [ I<argument> ... ]
=head1 DESCRIPTION
The B<printf> command uses the first argument as the format that describes
how to print the remaining arguments. Unlike the standard
printf(1) command, this one uses the Perl version.
See L<perlfunc/sprintf> for details.
=head1 RESTRICTIONS
This command should not be used in setuid programs as it does not run
untaint its argments and will trigger errors like C<Insecure dependency
in eval while running setuid at /opt/ppt/bin/printf line 16.>
=head1 SEE ALSO
printf(3), L<perlfunc/sprintf>
=head1 AUTHOR
Tom Christiansen, I<tchrist@perl.com>.
=head1 COPYRIGHT and LICENSE
This program is copyright (c) Tom Christiansen 1999.
This program is free and open software. You may use, modify, distribute,
and sell this program (and any modified variants) in any way you wish,
provided you do not restrict others from doing the same.