On Thu, Apr 11, 2002 at 11:13:44AM -0400, Jeff 'japhy' Pinyan wrote:
> On Apr 11, Jeff 'japhy' Pinyan said:
>
> >On Apr 11, Paul Makepeace said:
> >
> >>The task is to find the first differing character given two strings.
> >
> >You can get a little niftier if you're using Perl 5.6:
> >
> > ($a^$b)=~/^\0*/&&$+[0]
>
> Duh. Remove the ^ and change the && to * and you save two chars:
>
> ($a^$b)=~/\0*/*$+[0]
>
> The regex always succeeds -- thus, always returns 1.
Yeah, but does Perl actually garantee it will evaluate the
left operand of arithmetic operators first? If so, I cannot
find it in the documentation.
Luckely, there's a 1-character length operator that is documented
to first evaluate the left operand, then the right: ,
($a^$b)=~/\0*/,$+[0]
If you actually want to assign the result, you'd have to write it as:
($a^$b)=~/\0*/,$x=$+[0]
Abigail