in reply to Should string inequality operators return the point the of divergance?

I doubt perl will be changed to support such behaviour, since it is very rarely required and the information can quite easily be found by other means.

Here's one way to do it:

($s1 ^ $s2) =~ /[^\0]/ and return $-[0];

Hugo

  • Comment on Re: Should string inequality operators return the point the of divergance?
  • Download Code

Replies are listed 'Best First'.
Re^2: Should string inequality operators return the point the of divergance?
by Corion (Patriarch) on Oct 15, 2004 at 12:58 UTC

    Except, of course for

    $s1 = "\0"; $s2 = $s1 x 2; my $diff_pos = ($s1 ^ $s2) =~ /[^\0]/ ? $-[0] : undef; print defined $diff_pos ? "diff_pos says the strings differ at $diff_pos\n" : "diff_pos says the strings are equal.\n"; print $s1 eq $s2 ? "and Perl says they are equal\n" : "and Perl says they are not equal\n";