You might be interested in the "defined" function.
Code:
if($string) {
# string exists and evaluates as true
} elsif(defined $string) {
# string exists but evaluates as false
} else {
# string doesn't exist
}
Also, you can use numerical comparisons directly on strings, if they consist of just a number Perl will treat them as a number. On the other hand, you can use the "eq" operator to test equality as a string. (All the numerical comparison operators have string versions)
Code:
$number = 2;
$number_string = "02";
if ($number == $number_string) {
print "Variables are numerically equal.\n";
}
if ($number eq $number_string) {
print "Variables are equivalent strings.\n";
}
Run this and you'll see that the first statement is printed but not the second.