start page | rating of books | rating of authors | reviews | copyrights

Learning Perl on Win32 Systems

Learning Perl on Win32 SystemsSearch this book
Previous: 15.2 Extracting and Replacing a Substring Chapter 15
Other Data Transformation
Next: 15.4 Advanced Sorting
 

15.3 Formatting Data with sprintf( )

The printf function is sometimes handy when used to take a list of values and produce an output line that displays the values in controllable ways. The sprintf function is identical to printf for its arguments, but returns whatever would have been output by printf as a single string. (Think of it as "string printf .") For example, to create a string consisting of the letter X followed by a five-digit zero-padded value of $y , simply use this:

$result = sprintf("X%05d",$y);

See Chapter 6, Basic I/O , or Chapter 3 of Programming Perl for a description of the format strings understood by printf and sprintf .


Previous: 15.2 Extracting and Replacing a Substring Learning Perl on Win32 Systems Next: 15.4 Advanced Sorting
15.2 Extracting and Replacing a Substring Book Index 15.4 Advanced Sorting