Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!ncar!gatech!mcnc!uvaarpa!mmdf From: worley@compass.com (Dale Worley) Newsgroups: comp.lang.perl Subject: Sluggish patterns. Message-ID: <1991Apr5.194345.10811@uvaarpa.Virginia.EDU> Date: 5 Apr 91 19:43:45 GMT Sender: mmdf@uvaarpa.Virginia.EDU (Uvaarpa Mail System) Reply-To: worley@compass.com Organization: The Internet Lines: 44 From: flee@cs.psu.edu (Felix Lee) Okay. Now how do you make it recursive? sub ctw { local($cookie, $monster) = @_; while (! $done) { &eat() if /$cookie/; &run() if /$monster/; } } $cookie and $monster change infrequently, but they may change in either &eat or &run. Either &eat or &run may call &ctw recursively with random parameters. The following code comes to mind, although I don't know if it is correct: $old_cookie = $old_monster = 'something invalid'; sub ctw { local($cookie, $monster) = @_; local($old_cookie, $old_monster); local(*cookie, *monster); while (! $done) { eval "sub cookie { &eat() if /$cookie/o; }" if $cookie ne $old_cookie; &eat() if /$cookie/; eval "sub monster { &run() if /$monster/o; }" if $monster ne $old_monster; &run() if /$monster/; } } When a recursive call of ctw occurs, &cookie and &monster are saved, along with $old_cookie and $old_monster. Dale Dale Worley Compass, Inc. worley@compass.com -- He divines remedies against injuries; he knows how to turn serious accidents to his own advantage; whatever does not kill him makes him stronger. -- Friedrich Nietzsche