Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!ncar!gatech!usenet.ins.cwru.edu!ncoast!allbery From: allbery@NCoast.ORG (Brandon S. Allbery KF8NH) Newsgroups: comp.lang.perl Subject: Re: Manipulating strings Message-ID: <1991May23.223356.10387@NCoast.ORG> Date: 23 May 91 22:33:56 GMT References: Reply-To: allbery@ncoast.ORG (Brandon S. Allbery KF8NH) Followup-To: comp.lang.perl Organization: North Coast Public Access Un*x (ncoast) Lines: 34 As quoted from by setzer@matagh.ncsu.edu (Th'PoC): +--------------- | 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. +--------------- Not for iterating over multiple objects in step, but: open(A,'A'); $/ = undef; @a = unpack('c*',); close(A); # do the same for B, C, D while (($a,$b,$c,$d)=(scalar(shift(@a)),scalar(shift(@b)),scalar(shift(@c)), scalar(shift(@d)))) { # compare $a, $b, $c, $d } WARNING: this is incredibly wasteful of memory. Were your files not small, this would cause problems. But for short files it should be REAL fast. Basically, we pull each file into memory, with the unpack(c*) splitting it into arrays of characters. Then the shift pulls off each character in turn. ++Brandon -- Me: Brandon S. Allbery KF8NH: DC to LIGHT! [44.70.4.88] Internet: allbery@NCoast.ORG Delphi: ALLBERY uunet!usenet.ins.cwru.edu!ncoast!allbery