Re: WHY are args for sprintf in scalar context?
- From: Mirco Wahab <wahab-mail@xxxxxx>
- Date: Wed, 31 Oct 2007 17:11:52 +0100
w.c.humann@xxxxxxxx wrote:
But *why* are args for printf in array context and for sprintf in
scalar context? Especially if it's "not what I probably mean" and
"almost never useful". It's not like Perl to make easy things
harder...
This seems to be old news ;-)
http://www.perl.com/pub/a/1999/11/sins.html#2
http://www.perl.com/doc/manual/html/pod/perltrap.html#Context_Traps_scalar_list_con
IIRC, this distinction (printf/sprintf) came in
after porting from Perl4 to Perl5 because printf
accepts an optional filehandle as first argument
and sprintf allows format construction by subroutine
return value there. One of Perls oddities, true.
...
@a = ("%s %s\n", qw/foo bar/);
print sprintf shift @a, @a;
...
Regards
M.
.
- References:
- WHY are args for sprintf in scalar context?
- From: w . c . humann
- WHY are args for sprintf in scalar context?
- Prev by Date: !Help: can't get into perl -MCPAN -e shell
- Next by Date: Re: Printing to a Windows printer.
- Previous by thread: WHY are args for sprintf in scalar context?
- Next by thread: Printing to a Windows printer.
- Index(es):
Relevant Pages
|