Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!lll-winken!taco!taco.cc!setzer From: setzer@matagh.ncsu.edu (Th'PoC) Newsgroups: comp.lang.perl Subject: Manipulating strings Message-ID: Date: 23 May 91 18:00:13 GMT Sender: news@ncsu.edu (USENET News System) Organization: The Chebychev Church of Probability Lines: 29 X-Communicated: That royal king-type dude that had Becket snuffed The problem: I have four files of identical length (< 5k). Each contains 8 bit data, but do not contain any of `A'..`Z'. At any fixed offset into each file, either 1) all four characters are identical, or 2) one or more of the characters has the eighth bit set. I want to generate an "overlay", i.e., if (1), output the character; if (2), output a letter in `A'..`P' that will tell me which files had the eighth bit set. The [*ugly*] solution: I `open'ed the four files, slurped each of them into an array, and looped over the length of the array: -- open(A, "< a") || die "can't open 'a'"; @a=split(//,join("",)); # do the same for files "b", "c", and "d" for ($i=0; $i < $#a+1; $i++) { # do the `if's on `ord($a[$i])&0x80' etc. -- The question: Is there a "prettier" way to do this? (There must be. Isn't there a perl axiom that if you have to use an indexing variable, you're doing it the "wrong" way?) It comes down to simple string manipulation, but I can't see a way to use any of the implicit looping constructs (`for (@a)', `foreach ...'). I would appreciate insight into an alternate way to solve the problem. Thanks. Wm. -- If the fundamentalists don't hate you, you have the wrong lifestyle. -- James Nicoll