in reply to is behaviour undefined for string comparision with ==

== numifies its arguments. Non-numeric strings numify as 0 so all such strings equal each other and equal 0 when using ==. Consider:

use strict; #use warnings; sub match { my ($lhs, $rhs) = @_; print "$lhs == $rhs\n" if $lhs == $rhs; print "$lhs != $rhs\n" if $lhs != $rhs; } match ('0', '1'); match ('0', '0'); match ('1', '1'); match ('0xxx', '1xxx'); match ('0xxx', '0xxx'); match ('0', 'YYY'); match ('xxx', 'yyy'); match ('yyy', 'YYY');

Prints:

0 != 1 0 == 0 1 == 1 0xxx != 1xxx 0xxx == 0xxx 0 == YYY xxx == yyy yyy == YYY

Note that warnings are not enabled, otherwise you will get a bunch of warnings at runtime.


DWIM is Perl's answer to Gödel