Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Ok, here's an easy one

by abitkin (Monk)
on Sep 08, 2002 at 19:53 UTC ( [id://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.)

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-03-29 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found