P
pkassies
Hello everybody,
I need to strip "90.00" back to "90".
I wrote the following program
#!/perl
$item = "90.0";
print &strip_dot($item);
sub strip_dot
{
print "1 - $_[0]\n";
if ($_[0] =~ m/./)
{
print "2 - $_[0]\n";
return substr ($_[0], 0, index($_[0],"."));
} else
{
print "3 - $_[0]\n";
return "$_[0]";
}
}
its output is:
1 - 90.0
2 - 90.0
90
Great that works.
but if I make $item = "90";
the output is:
1 - 90
2 - 90
9
Hmm, that is not what I want.
The if statement should generate FALSE and it shouldn't be stripped to
9.
How can I solve this?
Any help is appreaciated.
I need to strip "90.00" back to "90".
I wrote the following program
#!/perl
$item = "90.0";
print &strip_dot($item);
sub strip_dot
{
print "1 - $_[0]\n";
if ($_[0] =~ m/./)
{
print "2 - $_[0]\n";
return substr ($_[0], 0, index($_[0],"."));
} else
{
print "3 - $_[0]\n";
return "$_[0]";
}
}
its output is:
1 - 90.0
2 - 90.0
90
Great that works.
but if I make $item = "90";
the output is:
1 - 90
2 - 90
9
Hmm, that is not what I want.
The if statement should generate FALSE and it shouldn't be stripped to
9.
How can I solve this?
Any help is appreaciated.