Unlike strongly typed languages, Perl doesn't distinguish between types of
scalar data, or rather, it massages it into the proper data depending on
the context you're in. Meaning if I do this:
my $sum = 1 + 1;
now, $sum contains a number: 2;
if I know say:
print "$sum\n";
Perl automatically changes the data type of $sum to a string for the print
function.
This means you have to be careful when you compare data. To force a
variable into number context you can do
$sum += 0;
Now sum is a number (if it only contains a number, if it contains data
which cannot be made into a number, then you get zero);
To be sure you have only numbers in your variable, you can use a regular
expression:
print "Not a number!\n" if($sum =~ /[^\d]/);
Now, you can use the proper operators to check your data
for numbers, use + - > < == !=, etc
print "Sum is 0\n" if($sum == 0);
print "Sum is less than 5\n" if($sum < 5);
for strings use eq, ne, lt, gt, etc
print "Sum is 'foo'" if($sum eq "foo");
At 15:05 25.06.2001 +0200, Stéphane JEAN BAPTISTE wrote:
>Hi!
>
>I get a value from a URL and I put it into a variable.
>I have a loop (while) with a value which have different values.
>The problem is that when I compare the first and the second value: If
>they're really equals, the program say they are'nt.
>
>Is ther a function to convert a value into an integer ?
>
>tks
>
>(sorry for my english :-) )
Aaron Craig
Programming
iSoftitler.com