The stupid question is the question not asked | |
PerlMonks |
Re^3: Printing a very small numberby kcott (Archbishop) |
on Aug 17, 2013 at 05:16 UTC ( [id://1049816]=note: print w/replies, xml ) | Need Help?? |
The sprintf documentation contains details of the formats; these are not shown in the printf documentation. So, as it was the sprintf formatting that I was explaining, it seemed appropriate to use sprintf in my example code. More importantly though, I made a conscious decision to not use printf in my examples. That function has a number of gotchas which aren't specifically related to the actual formatting and which I didn't want to have to explain. The printf documentation is short: just three paragraphs. The first gotcha, noted in the very first sentence, has tripped you up! Here's what happens if I substitute my 'print sprintf' with your ("Why not simply") 'printf':
I'll also draw your attention to the last printf paragraph: "Don't fall into the trap of using a printf when a simple print would do. The print is more efficient and less error prone." Finally, I use "=>" insted of "," for clarity; particularly when separating different types of arguments. If you look at my posts, you'll find many examples of this kind of thing:
I find it makes the code easier to read and, when necessary, easier to debug. There's a clear delineation between the first argument, which affects how the function operates, and the remaining arguments, which specify what the function operates on. -- Ken
In Section
Seekers of Perl Wisdom
|
|