) function,
except that, instead of printing formatted text, it returns a scalar character
variable containing that printed text.
Suppose we have an array containing prices, and we wish to calculate taxes on these prices, based on a tax rate of 7.5%. If we simply compute the taxes, and print the resulting variables, we may print numbers with more than two decimal places, which is inappropriate. We could create a corresponding array of formatted taxes as follows:
foreach $p (@prices){
push(@ftaxes,sprintf("%5.2f",$p * 0.075);
}
Each of the elements of @ftaxes will be of length 5, right justified
with two decimal places, making them suitable for printing in a table.