develooper Front page | perl.perl5.porters | Postings from September 2011

Re: [perl #100190] RFE: fix sprintf to be consistent with printf andbe useful!

Thread Previous | Thread Next
From:
Eric Brine
Date:
September 27, 2011 23:10
Subject:
Re: [perl #100190] RFE: fix sprintf to be consistent with printf andbe useful!
Message ID:
CALJW-qEdL0-r3Fs8vox0e10i=h5H1g-zfJBkLxL=qq0oXKx5Fg@mail.gmail.com
On Tue, Sep 27, 2011 at 4:36 PM, Linda Walsh <perlbug-followup@perl.org>wrote:

> Is there some **REAL** good reason why sprintf should not behave/
> be compatible with printf?


Actually, printf is really the odd one. Builtins tend to have precise
prototypes. printf doesn't have a prototype because of it's special parsing
rules (e.g. printf { $fh } $pat, @args).

If there was something to fix, I'd lean towards changing printf. The fact
that things can go horribly wrong when you don't pass a format is a good
thing.


Ways of using sprintf when the format is in $arg[0]:

my $format = shift(@args);
sprintf($format, @args)

or

sprintf($args[0], @args[1..$#args])

or

sprintf(shift(@args), @args)

Thread Previous | Thread Next


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