SPUG: "Programming Challenge"

Yitzchak Scott-Thoennes sthoenna at efn.org
Wed Dec 17 19:12:49 CST 2003

Avoid loops at all costs (or keep them in C where they belong):

use Encode;
print encode("UCS-2LE", $LSB) ^ encode("UCS-2BE", $MSB);

This works by "encoding" each string as little- or big-endian 2 bytes
per character (so each string will have all the odd or all the even
bytes null) then stringwise-xoring them together.

Using syswrite may be faster.

More information about the spug-list mailing list