RolandGunslinger has asked for the wisdom of the Perl Monks concerning the following question:

Take a look at this script;
#!perl use strict;use warnings; use Time::localtime; print "substr month= " . (substr("0" . localtime->mon() + 1, -2)) . "\ +n"; print "substr day= " . (substr("0" . localtime->mday(), -2)) . "\n"; print "sprintf month= " . (sprintf "%02d", localtime->mon() + 1) . "\n +"; print "sprintf day= " . (sprintf "%02d", localtime->mday()) . "\n";
It returns the following;
>perl substr month= 1 substr day= 09 sprintf month= 01 sprintf day= 09
Now, I know the first two lines are not a good way to pad. I found some nodes on Perlmonks that showed a better way, which is the last two lines. The problem is I'm perplexed as to the first result. Why does substr month only return a 1 instead of 01?
I'm using ActiveState Perl 5.8.0 running under Win32. Thanks.