We don't bite newbies here... much | |
PerlMonks |
Re: Adding Leading Zerosby seattlejohn (Deacon) |
on Sep 27, 2002 at 18:22 UTC ( [id://201290]=note: print w/replies, xml ) | Need Help?? |
Of course the sprintf solution is completely sensible, but in the interest of TMTOWTDI and a little extra exposure for the poor underappreciated x operator, this will work too: print "0" x (10-length($thing)) . $thing; And yes, if length($thing) should happen to be larger than 10, the x treats the negative second operand as if it were zero.
In Section
Seekers of Perl Wisdom
|
|