Table 5-2. Compare values | Expression | Value | | "12.0" == 12 | TRUE | | "12.0" eq 12 | FALSE | | 2 < 3 | TRUE | | 2 lt 3 | TRUE | | 12 > 3 | TRUE | | 12 gt 3 | FALSE ! | | "" == "hello" | TRUE ! (Warning) | | "" eq "hello" | FALSE | | "hello" == "world" | TRUE ! (Warning) | | "hello" eq "world" | FALSE |
When reading from STDIN you can always expect a string Example 5-12. examples/scalars/is_empty_string.pl #!/usr/bin/perl
use strict;
use warnings;
my $input = <STDIN>;
chomp $input;
if ($input == "") { # wrong! use eq
# empty string
}
If you are interested in on-site trainings by the author, please
contact me directly.
|