⭐ in reply to How do I compare two strings?
== tests equality for numbers.if ($string1 eq $string2){ print"\$string1 is equal to \$string2\n"; } elsif ($string1 lt $string2){ print"\$string1 is less than \$string2\n"; } elsif ($string1 gt $string2){ print"\$string1 is greater than \$string2\n"; }
You can also use the cmp operator, which is the non-numerical equivalent of the <=> operator:
$result = $string1 cmp $string2;
$result will be:
|
|---|