Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!sdd.hp.com!cs.utexas.edu!uunet!paralogics!shaw From: shaw@paralogics.UUCP (Guy Shaw) Newsgroups: comp.lang.perl Subject: How about a finicky printf()? Keywords: printf, format string, bounds checking Message-ID: <430@paralogics.UUCP> Date: 23 Jun 91 05:43:26 GMT Organization: Paralogics; Santa Monica, CA Lines: 29 How about a finicky printf() ? The Perl implementation of printf() does not do any checking to ensure that the number of arguments given matches the number called for in the format string. Extra arguments are ignored. Arguments needed beyond the number given are silently supplied as though a null value were given. So, the argument list is, in effect, padded with null values. perl -e 'printf "%d %d\n", 1, 2, 3' => 1 2 perl -e 'printf "%d %d\n", 1' => 1 0 Awk complains about this at run-time. Perl ought to be able to complain at run-time. I would like to see Perl do awk one better and do a bit of compile-time analysis, where possible, as well. Sure, you couldn't do that for format strings that are variables, and Perl has things like eval() that can make things a bit trickier; but the majority of times, in practice, format strings are constants. If performance degradation is part of the rationale for not doing this in Perl, then I would suggest doing the checking only when the -w option is turned on. Just Another Perl Suggestion from Just Another Perl Dilettante, -- Guy Shaw Paralogics paralogics!shaw@uunet.uu.net or uunet!paralogics!shaw