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

hai monks,
i want to print only from 0 to 999.
if it is 0 it should print 000
if it is 12 it should print 012
if it is 2 it should print 002
the numbers may be anything between 0 to 999.But front spaces should be padded with zero or zeros

Edit: g0n - removed code tags bracketing entire post

Replies are listed 'Best First'.
Re: help needed in printing the numbers
by Corion (Patriarch) on Apr 05, 2006 at 09:23 UTC

    perldoc -q pad points out the sprintf function:

    my $padded = sprintf "%03s", $number;
Re: help needed in printing the numbers
by murugu (Curate) on Apr 05, 2006 at 09:43 UTC

    use sprintf.

    my $result = sprintf "%03d", $number;

    Regards,
    Murugesan Kandasamy
    use perl for(;;);