On Apr 11, Paul Makepeace said:

>The task is to find the first differing character given two strings.

The "leading common substring" problem was a topic at YAPC 99, I believe.

>#london.pm quickly came up with,
>
>  ($a ^ $b) =~ /^(\0*)/ && length $1
>
>with the possible caveat that this could be wasteful for large, and
>especially early differing strings. It is nice that it's an expression
>though.

You can get a little niftier if you're using Perl 5.6:

  ($a^$b)=~/^\0*/&&$+[0]

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]

Reply via email to