Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Ok, here's an easy one

by abitkin (Monk)
on Sep 08, 2002 at 19:53 UTC ( #196085=note: print w/ replies, xml ) Need Help??

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.)

Comment on Re: Ok, here's an easy one
Download Code
Replies are listed 'Best First'.
Re: Re: Ok, here's an easy one
by I0 (Priest) on Sep 09, 2002 at 03:13 UTC
    $num = substr("00".$num,-2);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://196085]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2015-11-28 16:56 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (743 votes), past polls