[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [Fun With Perl] Re: How to swap $p and $q without $tmp



On Fri, Jun 11, 1999 at 10:51:39AM -0400, John Porter wrote:
> Roland wrote:
> > 
> >  $q ^= $p;
> >  $p ^= $q;
> >  $q ^= $p;
> > 
> > BTW, why does this work with strings of different length?
> > Deep Perl magic?
> 
> If you inspect the variables after each step, you'll discover that
> the shorter one is padded with null characters *on the left* before
> the first XOR.  This has the effect, after the last XOR, of the other
> variable, the one that had been longer, being padded will nulls on
> the right, which Perl then (apparently) discards.  Not terribly magic;
> more like "automagic".
> 

Eh, I don't see those results...  Bitwise string operations always null-pad
on the right, not on the left.  At the end, the shorter string is
null-padded on the right, and those nulls are not discarded.

Could you explain further what you meant by the above?

Ronald

==== Want to unsubscribe from this list? (Don't you love us anymore?)
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org