Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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 having an uproarious good time at the Monastery: (9)
As of 2015-10-13 23:41 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (317 votes), past polls