help needed in printing the numbers
singam
created: 2006-04-05 05:20:57
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
Re: help needed in printing the numbers
created: 2006-04-05 05:23:14

perldoc -q pad points out the [doc://sprintf] function:

my $padded = sprintf "%03s", $number;
Re: help needed in printing the numbers
created: 2006-04-05 05:43:58

use [perldoc://sprintf].

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

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

perlmonks.org content © perlmonks.org and Corion, murugu, singam

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03