home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5713 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.5 KB  |  39 lines

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