Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!timbuk!shamash!rrr From: rrr@u02.svl.cdc.com (Rich Ragan) Newsgroups: comp.lang.perl Subject: Array modification rules (?) Keywords: splice perl array modifications Message-ID: <29924@shamash.cdc.com> Date: 17 Jan 91 18:06:44 GMT Sender: usenet@shamash.cdc.com Reply-To: rrr@svl.cdc.com Organization: Control Data Corporation, Silicon Valley Operations Lines: 27 I often want to modify the array that is being used as the iterator for a loop within that loop. Some examples, include - Scan the argument vector and remove or add args based on what was specified. - Scan an array and remove "uninteresting" elements To be safe, I have always used a temporary array in the past. Is this necessary or are there well defined rules for adding/deleting elements from the array being used as the iterator within the scope of the iteration? Will this become patently obvious when my copy of "The Book" arrives? In any event, I could not contain my curiosity any longer. Assuming the rules are formalized and "intuitive" it could be useful for a lot of cases. I played with the following little piece to determine that there is some method to what happens. @a=split(//,"%xJaubsctd eafngohtihjekrl mPneorplq rhsatcukvewrx"); for (@a) {splice(@a,0,1);$x .= $_;} print "$x\n"; -- Richard R. Ragan rrr@svl.cdc.com (408) 496-4340 Control Data Corporation - Silicon Valley Operations 5101 Patrick Henry Drive, Santa Clara, CA 95054-1111