Change %6s to %06s and it will pad with zeros.

Wags ;)

-----Original Message-----
From: Schoeneman, Carl [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 26, 2001 12:40
To: Perl Beginners (E-mail)
Subject: Pad Number with Leading Zeros


Hello.
 
Is there a way to pad a number with leading zeros with 1 command rather than
the 2 I used below?  It looks like you're supposed to be able to zero-fill
with sprintf but I couldn't figure it out.
 
#!/bin/perl -wd
 
$f = 1234;
 
$g = sprintf "%6s", $f;    
$g =~ s/ /0/g;                
 
print "$f\n";
print "$g\n";
 
 
 
~Carl

Reply via email to