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

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

Thread Next
From:
Father Chrysostomos via RT
Date:
October 15, 2011 23:02
Subject:
[perl #100190] RFE: fix sprintf to be consistent with printf and be useful!
Message ID:
rt-3.6.HEAD-31297-1318744933-1689.100190-15-0@perl.org
On Wed Oct 05 14:38:47 2011, Hugmeir wrote:
> On Sat, Oct 1, 2011 at 1:18 PM, Linda Walsh <perl-diddler@tlinx.org>
wrote:
> 
> > [...]You CAN
> > pass an array to it, it just is BAD code -- it certainly doesn't
throw an
> > syntax error -- it allows an array there, which, "___is [almost]^ never
> > useful__".  [...]
> >
> >
> >
> You know.
> That's actually true.
> There's a bug in a handful of modules because of this; See
> http://grep.cpan.me/?q=sprintf\s*\%28%3F\s*\%40 and
> http://www.google.com/codesearch#search/&q=sprintf\s*\%28
> ?\s*\@%20lang:^perl$&type=cs
> Changing it takes two lines of code (regen/opcodes and t/op/cproto.t)
and a
> regen, plus doc/delta changes. I was under the impression that @ is a
> superset of $@, so there's no lost functionality either -- I'm running (a
> very slow) make test right now, and nothing is failing, so this behavior
> wasn't even tested for! (or I haven't reached that part yet, but
> op/sprintf.t and op/sprintf2.t passed without issues)
> 
> And it's not like prototypes haven't been changed before (to tchrist's
> chagrin, e.g.
> http://www.nntp.perl.org/group/perl.perl5.porters/2011/04/msg171420.html).
> 
> So eh, any reason why this can't be changed?

Consider sprintf(get_format(), @args).  get_format might return
something else in list context.  That’s the kind of breakage we don’t want.

Also, does your experiment really work, or do you mess up the stack in
cases like this?

@a = ('%d', sprintf());

> If anyone needs a compat layer,
> I imagine it's trivial enough to provide through
Classic::Perl/Modern::Perl,
> or somesuch.

What would prototype(\&CORE::sprintf) return?


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