#How to I convert a string to a number
sub atoi {
my $t;
foreach my $d (split(//, shift())) {
$t = $t * 10 + $d;
print "$t\n";
}
return $t;
}
$number = atoi("123");
print "string '123' number value is $number";
sub atoi {
my $t;
foreach my $d (split(//, shift())) {
$t = $t * 10 + $d;
print "$t\n";
}
return $t;
}
$number = atoi("123");
print "string '123' number value is $number";
No comments:
Post a Comment