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:
Ricardo Signes
Date:
September 28, 2011 16:48
Subject:
Re: [perl #100190] RFE: fix sprintf to be consistent with printf andbe useful!
Message ID:
20110928234608.GA27467@cancer.codesimply.com
* Linda W <perl-diddler@tlinx.org> [2011-09-28T19:27:23]
> >
> >my @arr = ( "%s\n", "hullo" );
> >my $result = sprintf $arr[0], $arr[1..$#etc];
> >say $result;
> [ ... ]
>
> Ya know...for someone who talks like what they think they know what they are
> talking about, they might wanna check their examples before telling people
> that they can do "XXX", cuz your example doesn't work (and I wasted a bit of
> time thinking you knew what you were talking about!  (dictionary, gullible:
> me).

There is no call for this kind of attitude.  If we're all going to work
together, I think we can all try to be polite.

The response had a small typo.  It just shows that turning (@arr) into ($head,
@rest) is trivial, and that there is no massive machinery needed to do it.

It may be unfortunate that this builtin can't work the way you want, but it has
been this way for ages and is not really something that can be changed without
serious disruption.  Or, to be more blunt, I am fairly certain that it is
simply not going to change.  That's okay because you can write:

  sub mysprintf { sprintf( $_[0], @_[ 1 .. $#_ ] ); }

  my @arr = ('Foo %s', 123);
  print mysprintf(@arr);

The correct action is probably the addition of "printf EXPR" to printf's docs,
and a caveat about the lack of that form to sprintf's docs.

-- 
rjbs

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