On Fri, Jan 05, 2007 at 11:16:58AM +0530, Dharshana Eswaran wrote:
> Hi,
> 
> I have an array which reads as follows:
> 
> @array = (01, 45,  02, 57,  03);
> 
> When i try to print this array, it prints the single digit value as
> 
> 1, 45, 2, 57, 3
> 
> But i want it to print like
> 
> 01, 45, 02, 57, 03
> 
> I can use if condition and then try printing the value as double digit, but
> i was thinking of a better way. Can anyone suggest me a more efficient way?


perldoc -f sprintf

Try this.
----------------------------------------------------------
#!/usr/bin/perl

use strict;
my $result;
my @array = (01, 45,  02, 57,  03);

foreach (@array){ $result =sprintf("%02d", $_);print "$result\n"}
----------------------------------------------------------

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to