Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ucbvax!csd.uwo.ca!clipper From: clipper@csd.uwo.ca (Khun Yee Fung) Newsgroups: comp.lang.perl Subject: Subroutine parameters Message-ID: <9105312319.AA21073@no11sun.csd.uwo.ca> Date: 31 May 91 23:19:05 GMT Sender: rwh@ucbvax.BERKELEY.EDU Lines: 56 I am using perl to write a program generator. This program has a few recursive subroutines using more than one array passed among them. To make sure the subroutines do not alter the content of the arrays, I use something like: @arg1 = @dimen1; @arg2 = @dimen2; &traverse($level); . . . sub traverse { local(@dimen1) = @arg1; local(@dimen2) = @arg2; local($level) = @_; . . . @arg1 = @dimen1; @arg2 = @dimen2; &traverse($level); . . } As my program is getting rather big, I am getting worried about missing the @argn = @array part of this method, among other things. I did get quite a lot of minor bugs because of misspelling etc. Is there a better way of doing this? Should I use eval and pass the names of the arrays to the subroutine and eval them to get the real arrays and then copy them in local arrays? Is it profitable to have a parameter list for a subroutine that will do exactly this? Like: &traver($level, @dimen1, @dimen2); sub traverse($level1, @dimen1, @dimen2) { local($level2, @therest) = @_; where we have the exact same result; $level1 is the same as $level2, and @therest contains @dimen1 and @dimen2, just like the current perl? I know the program I am writing is not really ideal for perl. But to convert it to C is a very big headache as I use quite a few evals... Thanks for any ideas. Khun Yee -- Name: Khun Yee Fung Email: clipper@csd.uwo.ca Paper mail: Department of Computer Science, Middlesex College The University of Western Ontario, London, Ontario, N6A 5B7 CANADA