http://www.perlmonks.org?node_id=196085


in reply to Zero padding numbers (was: Ok, here's an easy one)

sprintf is too easy, here's a fun way.

#!/usr/bin/perl my $num = 5; $num = substr("00",2-length($num)) . $num if length($num)<2; print $num;


I only mention it, becuase sometimes you want to pad with something other than 0's (for example "." when doing a TOC listing.)