Browse - programming tips - perl case insensitive compareDate: 2008feb14 Language: perl Q. How can I do a case insensitive string compare? A. Here's a pretty nice way to do it: sub ceq($$) { my($a, $b) = @_; $b = quotemeta($b); # For safety return $a =~ m/^$b$/i; # Using the i is key } sub cne($$) { my($a, $b) = @_; return ! ceq($a, $b); } # Example use sub main() { if (ceq('apple', 'aPPle')) { print "same\n"; } else { print "different\n"; } } Add a commentSign in to add a comment |