2.3. Width and Max Width

One can apply an optional width and max width (or for floating point numbers - precision), specifier for the conversion flags. This is a number followed by an optional dot and another number.

Here are some examples:

#!/usr/bin/env perl

use strict;
use warnings;

printf "<%10s>\n", "Hello";       # Prints <     Hello>
printf "<%-10s>\n", "Hello";      # Prints <Hello     >
printf "<%3.5s>\n", "Longstring"; # Prints <Longs>
printf "<%.2f>\n", 3.1415926535;  # Prints <3.14>

Written by Shlomi Fish