On Monday, Nov 10, 2003, at 13:13 US/Pacific, SilverFox wrote:
Hi all, i'm trying to figure out how to test if a number is five digits and
if not add zero/s in front to make it 5 digits. Any ideas?????
Examples:
444 = 00444 4120 = 04120 23 = 00023
there are two parts to your question, the later is answered with the sprintf - cf perldoc -f sprintf, as others have noted this leaves only the RE part
$token = sprintf("%05d", $token)
if ($token =~ /^\d+$/ );the 'if' condition is checking that the "$token" is all numeric from beginning to end, and if so it will sprintf() it.
ciao drieux
---
cf:
my @list = qw(
444
4120
23
bob
12345
123456
3bob
);
five_wide($_) foreach(@list);
#------------------------
#
sub five_wide
{
my ($token) = @_;
print "$token = ";
$token = sprintf("%05d", $token)
if ($token =~ /^\d+$/ );
print " $token \n";
} # end of five_wide
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
