in reply to sprintf format parameter required

Per perldoc -f sprintf:
Unlike printf, sprintf does not do what you probably mean when you pass it an array as your first argument. The array is given scalar context, and instead of using the 0th element of the array as the format, Perl will use the count of elements in the array as the format, which is almost never useful.

I can't comment on why it's that way (though I speculate that the difference is related to different internal prototypes), but that's the way it is, and it's documented. I'm sure someone can tell us why they were implemented identically in almost every way except this.


Dave


"If I had my life to live over again, I'd be a plumber." -- Albert Einstein

Replies are listed 'Best First'.
Re: Re: sprintf format parameter required
by shenme (Priest) on Oct 31, 2003 at 05:36 UTC
    Don't know how I missed it.   Sheesh, 'printf', 'sprintf', 'array', 'format'.   They really tried to reach me!