Re: mini-golf: first differing position

Yitzchak Scott-Thoennes <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Organization bs"d
Message-ID <[email protected]>
On Tue, Apr 20, 2004 at 09:59:46PM -0400, Bernie Cosell <[email protected]> wrote:
> On 20 Apr 2004 at 20:48, Craig S. Cottingham wrote:
> > I couldn't get that to work.
> 
> Really?  I cleaned it up a bit and it seems to work fine:
> 
> sub diff
> {   my $diff = $_[0] ^ $_[1];
>     my ($len) = $diff =~ /^([\0]*)[^\0]/ ;
>     return undef if not defined $len ;
>     return length $len;
> }

Perhaps he used numbers instead of strings.  It's a good idea to always
force the bitops to behave in the mode you want:
   my $diff = "$_[0]" ^ "$_[1]";
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.