Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!munnari.oz.au!mel.dit.csiro.au!yarra!melba.bby.oz.au!gnb From: gnb@bby.oz.au (Gregory N. Bond) Newsgroups: comp.lang.perl Subject: Calculating XOR checksums? Fast splitting? Message-ID: Date: 3 Jun 91 03:56:56 GMT Article-I.D.: leo.GNB.91Jun3135656 Sender: usenet@melba.bby.oz.au (news READER id) Organization: Burdett, Buckeridge and Young Ltd. Lines: 27 Nntp-Posting-Host: leo-gw Given a string, what is the fastest way to calculate the XOR of all bytes? here is what I used: $bcc = 0; grep ($bcc ^= $_, unpack("C" x length($sc_data), $sc_data)); But is there a batter way without having to construct and destroy the array? (I need this to be fairly quick...). And a second point, what is likely to be faster to split a string into several subfields? A regexp: $str =~ /(.{32})(.{24})(.{8})/; ($a, $b, $c) = ($1, $2, $3); or unpack: ($a, $b, $c) = unpack("c32 c24 c8", $str); or substr: $a = substr($str, 0, 32); $b = substr($str, 32, 24); $c = substr($str, 32 + 24, 8); Or something I haven't considered? Greg, performance weenie (at least for this application!) -- Gregory Bond, Burdett Buckeridge & Young Ltd, Melbourne, Australia Internet: gnb@melba.bby.oz.au non-MX: gnb%melba.bby.oz@uunet.uu.net Uucp: {uunet,pyramid,ubc-cs,ukc,mcvax,prlb2,nttlab...}!munnari!melba.bby.oz!gnb