Re: sprintf and printf in Perl



Chen Li wrote:

I want to print out a AoA. If I use printf I get what
I expect. If I use sprintf for string I get error
messages

What is making you think that printf() and sprintf() can be used
interchangably?


but the remaining still look OK. But If use
sprintf also for numbers I get nothing only error
messages. I look at the POD. It looks like sprintf and
printf are changeable to me.

WHAT part of the POD says that?

perldoc -f printf
printf FILEHANDLE FORMAT, LIST
printf FORMAT, LIST
Equivalent to "print FILEHANDLE sprintf(FORMAT,
LIST)", except that "$\" (the output record
separator) is not appended.

Any comments?

What about the above makes you think that you can replace printf with
sprintf or vice-versa?

Paul Lalli

.



Relevant Pages

  • Re: sprintf and printf in Perl
    ... While 'printf' print the result directly to screen. ... sprintf and printf in Perl ... Output2 from screen (use sprintf for string) ... Useless use of sprintf in void context at math9.pl ...
    (perl.beginners)
  • setting MAX characters emitted in printf() functions?
    ... Where printf() here is generic and refers to sprintf, fprintf, etc. ... 256 characters on some platforms a double is even larger than that, ... string containing the formatted variable if the desired field ...
    (comp.lang.c)
  • Re: setting MAX characters emitted in printf() functions?
    ... >Where printf() here is generic and refers to sprintf, fprintf, etc. ... C99 snprintf returns the number of characters that would have been ...
    (comp.lang.c)
  • Re: setting MAX characters emitted in printf() functions?
    ... > Where printf() here is generic and refers to sprintf, fprintf, etc. ... > 256 characters on some platforms a double is even larger than that, ... > string containing the formatted variable if the desired field ...
    (comp.lang.c)
  • Re: [missing the obvious?] ascii->int
    ... from a previous post i learned that the printf should be ... another paradigm shift for me... ... o studi a memoria e cerchi di elevarti socialmente o rimani una ...
    (comp.lang.awk)