On Thu, Apr 11, 2002 at 05:06:28PM -0400, Prakash Kailasa wrote: > On Thu, Apr 11, 2002 at 05:03:53PM -0400, Jeff 'japhy' Pinyan wrote: > > On Apr 11, Prakash Kailasa said: > > > > >On Thu, Apr 11, 2002 at 08:06:14AM -0700, Paul Makepeace wrote: > > >> The task is to find the first differing character given two strings. > > >> There is one obvious solution walking along using substr, > > > > > >($a^$b)=~y/\0// > > > > That isn't helpful, though -- that merely gives a count of how many > > characters were the same between the two. We need the position of the > > first difference. > > Hmm, wasn't the example given by Paul (original poster) giving the > same value? > > ($a ^ $b) =~ /^(\0*)/ && length $1
Whether they give the same value depends on the values of $a and $b. Try it with $a = 'abcdef' and $b = 'abCdef', for example. Ronald