I understand how printf works with numbers but i am a bit confused when it is used with strings.
in:
%-w.dx
I uderstand that % is the field specifier marker, and a minus sign means to align to the left, and that w is the TOTAL width of field.
My problem arises when ther is a decimal point (as in above) and a value for d (which i have seen written as "The total allowable width of the field FOR STRINGS). I dont understand the difference between w and d (above).
Example.
printf ("%-15.5s", $stringValue);
Here, the feild is 15 characters long, but what does the .5 mean.
Here, the feild is 15 characters long, but what does the .5 mean.
I'll try my best at explaining this.
The -15 sets the minimum field width to 15, with padding applied on the right side of the string value (any "positive" integer would apply padding to the left side of the string value). The .5 (a precision control) denotes that the string value will be truncated to a length of 5.
This may be better understood by running the following example in your browser and viewing the source to actually see the padding and control features doing their thing.
There's a way to make it work in MSIE but you don not want to go there.
It's best to run Perl from the command line but if you are developing something for the web then you will need a server, perhaps XAMPP.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
Bookmarks