home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!ferkel.ucsb.edu!piggy!chupchup
- From: chupchup@ferkel.ucsb.edu (Robert Earl)
- Subject: Re: Very tiny bug in printf? (perl 4.034)
- Message-ID: <chupchup.715552433@piggy>
- Organization: (EVIL!)
- References: <1992Sep3.020523.22087@aie.nl> <mcook.715536130@fendahl.dev.cdx.mot.com>
- Date: Thu, 3 Sep 1992 20:33:53 GMT
- Lines: 28
-
- mcook@fendahl.dev.cdx.mot.com (Michael Cook) writes:
-
- | hansk@aie.nl (Hans Kinwel) writes:
-
- | >I expected the following three lines to print out 08 two times.
-
- | >$val="8";
- | >printf ("%02s\n", $val);
- | >printf ("%02d\n", $val);
-
- | In _Standard C_ by Plauger and Brodie, they say "Following the percent
- | character (%), you can write zero or more flags: ... 0 -- to pad a conversion
- | with leading zeros after any sign or prefix, in the absence of any other
- | padding," which seems to be saying that you should get "08" for both.
-
- Actually, this behavior seems to be deemed undefined by the standard:
- "For d, i, o, u, x, X, e, E, f, g, and G conversions, leading zeros
- ... are used to pad the field width; no space padding is performed...
- For other conversions, the behavior is undefined."
-
- So printf, given "%02s", can do whatever it jolly well feels like
- doing, but hey, this is Perl, and Perl does what Perl does. :-)
-
- --
- "If you've got a pig that likes jumping fences, | robert earl
- you have to make its fence a lot higher all at | rearl@ucsd.edu
- once -- if you do it by increments, all you're | rearl@piggy.ucsb.edu
- doing is training a jumping pig." -Henry Spencer|
-