Two sets of relation operators. One is to compare numerically the other is to compare as strings, based on the ASCII table.
Table 2-1. Comparison Operators
| Numeric | String (ASCII) | Meaning |
| == | eq | equal |
| != | ne | not equal |
| < | lt | less than |
| > | gt | greater than |
| <= | le | less than or equal |
| >= | ge | greater then or equal |
3 == 4 # false '35' eq 35.0 # false '35' == 35.0 # true 13 > 2 # true 13 gt 2 # false !!! "hello" == "world" # true !!! Don't compare strings as if they were numbers! "hello" eq "world" # false "hello" == "" # true !!! Don't compare strings as if they were numbers! "hello" eq "" # false
Example 2-10. examples/scalars/comparison_operators.p6
#!/usr/bin/perl6 say 4 == 4 ?? "TRUE" !! "FALSE"; # TRUE say 3 == 4 ?? "TRUE" !! "FALSE"; # FALSE say "3.0" == 3 ?? "TRUE" !! "FALSE"; # TRUE say "3.0" eq 3 ?? "TRUE" !! "FALSE"; # FALSE say 13 > 2 ?? "TRUE" !! "FALSE"; # TRUE say 13 gt 2 ?? "TRUE" !! "FALSE"; # FALSE say "foo" == "" ?? "TRUE" !! "FALSE"; # TRUE say "foo" eq "" ?? "TRUE" !! "FALSE"; # FALSE say "foo" == "bar" ?? "TRUE" !! "FALSE"; # TRUE say "foo" eq "bar" ?? "TRUE" !! "FALSE"; # FALSE
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| if statement - comparing values | Up | Boolean expressions (logical operators) |