(question)
Question:
Answer:
Question:
#!/usr/bin/perl
$x = "moo";
if ($x == "") { print "Please supply input.\n"; }
else { print "You wrote '$x'\n"; }
This program prints "
The
Use the
Please supply input.
".
The
==
operator in Perl does not compare strings. So, unexpected
values may evaluate as equal. For example, 0 == "moo"
is true,
as is "moo" == "ribbit"
.
Use the
eq
operator to compare strings instead. Or, if you don't
know the type of the objects you're comparing, compare their type first and
then if they're the same, compare values with an appropriate operator.