develooper Front page | perl.perl5.porters | Postings from June 2015

[perl #125469] "redundant argument in printf" warning and computed field widths

Thread Previous
From:
James E Keenan via RT
Date:
June 24, 2015 02:16
Subject:
[perl #125469] "redundant argument in printf" warning and computed field widths
Message ID:
rt-4.0.18-17428-1435112177-1783.125469-15-0@perl.org
On Tue Jun 23 16:01:23 2015, karl@freefriends.org wrote:
> 
> This is a bug report for perl from karl@freefriends.org,
> generated with the help of perlbug 1.40 running under perl 5.22.0.
> 
> The perlfunc doc (aka http://perldoc.perl.org/functions/sprintf.html)
> has this example:
> 
> printf '<%*2$s>', "a", 6; # prints "<          a>"
> 
> Running it with perl -w, in perl 5.22.0, produces a warning:
> 
> Redundant argument in printf at try.pl line 1.
> 
> Maybe I'm missing something obvious, but it sure seems like both
> arguments are being used; the a is the value and the 6 is the field
> width.  So the warning seems incorrect.  Help?
> 
> Thanks,
> Karl (karl@freefriends.org)

I agree.

Relevant documentation from pod/perldiag.pod and pod/perlfunc.pod (blead):

#####
=item Redundant argument in %s

(W redundant) You called a function with more arguments than other
arguments you supplied indicated would be needed.  Currently only
emitted when a printf-type format required fewer arguments than were
supplied, but might be used in the future for e.g. L<perlfunc/pack>.
#####
Between the C<%> and the format letter, you may specify several
additional attributes controlling the interpretation of the format.
In order, these are:

=over 4

=item format parameter index

An explicit format parameter index, such as C<2$>.  By default sprintf
will format the next unused argument in the list, but this allows you
to take the arguments out of order:

  printf '%2$d %1$d', 12, 34;      # prints "34 12"
  printf '%3$d %d %1$d', 1, 2, 3;  # prints "3 1 1"
...
=item (minimum) width

Arguments are usually formatted to be only as wide as required to
display the given value.  You can override the width by putting
a number here, or get the width from the next argument (with C<*>)
or from a specified argument (e.g., with C<*2$>):

 printf "<%s>", "a";       # prints "<a>"
 printf "<%6s>", "a";      # prints "<     a>"
 printf "<%*s>", 6, "a";   # prints "<     a>"
 printf '<%*2$s>', "a", 6; # prints "<     a>"
 printf "<%2s>", "long";   # prints "<long>" (does not truncate)
#####
Thank you very much.
Jim Keenan

> ---
> Flags:
>     category=core
>     severity=medium
> ---
> Site configuration information for perl 5.22.0:
> 
> Configured by karl at Sat Jun 13 07:10:09 MDT 2015.
> 
> Summary of my perl5 (revision 5 version 22 subversion 0)
> configuration:
> 
> Platform:
>   osname=linux, osvers=2.6.32-504.16.2.el6.x86_64, archname=x86_64-
> linux
>   uname='linux frenzy.freefriends.org 2.6.32-504.16.2.el6.x86_64 #1
> smp wed apr 22 06:48:29 utc 2015 x86_64 gnulinux '
>   config_args='-d -e -Uinstallusrbinperl -Dprefix=/usr/local'
>   hint=recommended, useposix=true, d_sigaction=define
>   useithreads=undef, usemultiplicity=undef
>   use64bitint=define, use64bitall=define, uselongdouble=undef
>   usemymalloc=n, bincompat5005=undef
> Compiler:
>   cc='cc', ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-
> protector -I/usr/local/include -D_LARGEFILE_SOURCE
> -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2',
>   optimize='-O2',
>   cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector
> -I/usr/local/include'
>   ccversion='', gccversion='4.4.7 20120313 (Red Hat 4.4.7-11)',
> gccosandvers=''
>   intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678,
> doublekind=3
>   d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16,
> longdblkind=3
>   ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
> lseeksize=8
>   alignbytes=8, prototype=define
> Linker and Libraries:
>   ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
>   libpth=/usr/local/lib /usr/lib /lib/../lib64 /usr/lib/../lib64 /lib
> /lib64 /usr/lib64 /usr/local/lib64
>   libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
>   perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
>   libc=libc-2.12.so, so=so, useshrplib=false, libperl=libperl.a
>   gnulibc_version='2.12'
> Dynamic Linking:
>   dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
>   cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-
> protector'
> 
> 
> ---
> @INC for perl 5.22.0:
>     /usr/local/lib/perl5/site_perl/5.22.0/x86_64-linux
>     /usr/local/lib/perl5/site_perl/5.22.0
>     /usr/local/lib/perl5/5.22.0/x86_64-linux
>     /usr/local/lib/perl5/5.22.0
>     /usr/local/lib/perl5/site_perl/5.20.2
>     /usr/local/lib/perl5/site_perl/5.20.1
>     /usr/local/lib/perl5/site_perl/5.20.0
>     /usr/local/lib/perl5/site_perl/5.18.2
>     /usr/local/lib/perl5/site_perl/5.18.1
>     /usr/local/lib/perl5/site_perl/5.16.3
>     /usr/local/lib/perl5/site_perl/5.14.2
>     /usr/local/lib/perl5/site_perl
>     .
> 
> ---
> Environment for perl 5.22.0:
>     HOME=/u/karl
>     LANG (unset)
>     LANGUAGE (unset)
>     LC_ALL=C
>     LD_LIBRARY_PATH (unset)
>     LOGDIR (unset)
>     PATH=.:/u/karl/bin:/l/bin:/usr/local/gnu/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/sbin:/sbin:/usr/sbin:/usr/bin:/bin:/l/mailman/bin
>     PERL_BADLANG (unset)
>     SHELL=/bin/bash


-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=125469

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About