Saturday, June 27, 2009

Perl: Left padding an integer using sprintf

Using the function sprintf() of Perl, you can easily left pad any given integer number easily. The sprintf() function is similar to use like other programming languages. I'm giving an example of showing a given integer number with 5 field, where left sides will filled with zeros if any.


my $integer = 10;
$integer = sprintf("%05d", $integer);
print "$integer\n";


Just a simple left padding.

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...