in reply to Re: Re: Algorithm Pop Quiz: Sorting
in thread Algorithm Pop Quiz: Sorting

Sure, it looks cool. It's just wrong :)

The problem with xor on strings is it will extend short ones. There are now 0 bytes there that weren't there before, and length changes.

$ perl -e'$a="a"; $b="bbb"; $a^=$b; $b^=$a; $a^=$b; print "/$a/,/$b/\n +"; print length($a),"\n"; print length($b),"\n"' /bbb/,/a/ 3 3

--
Mike

Replies are listed 'Best First'.
Re: XOR swap bad...
by Jasper (Chaplain) on Mar 25, 2002 at 14:51 UTC
    Mike, thanks, I think. How odd. I had no idea this happened. That'll teach me. Still, I've never had a computer science lesson in my life, so how am I expected to know these things!?! :) Cheers, Jasper
      Hehe, to tell you the truth, I DO have a CS background, and I never would have known this happened in perl if I hadn't run into the string extension problem using the preserve_case routine from perlfaq6.
      --
      Mike