in reply to Re^2: Local $$_?
in thread Local $$_?

Now you can use a loop or a temporary array to set whatever values you want!

Cheers Rolf

Replies are listed 'Best First'.
Re^4: Local $$_?
by expresspotato (Beadle) on Mar 15, 2010 at 12:47 UTC
    Thank you LanX! You're correct in assuming this will be used in a loop. An FCGI Loop infact. Some older scripts were not designed with lexicallity in mind and simply make use of global variables if and when they're values are needed. Localizing these at the beginning of the FCGI Loop allowed me to run the given program under FCGI without re-writing it. Early indications show an improvement of over 500%. Although it is not a perfect solution - it seems to be working.
      Yeah I was expecting something like reusing old code.

      Glad if I was able to help! :)

      Cheers Rolf

      UPDATE: But you should do thorough testing to be sure about the side-effects! Be aware: In many cases testing and fixing resulting bugs aren't cheaper than rewriting ...

      Using lexical variables are almost always better!

      All you really needed was

      print "local \$$_ = \$$_;\n" for @listofvarnames;
      then you copy/paste
      local $blah = $blah; ...

      Although it is not a perfect solution - it seems to be working.

      The use of global variables is red flag. Your statement that "it seems to be working" also indicates that it doesn't come with a test suite, another red flag. I think now is a time to consider/plan to refactor this program.

      > You're correct in assuming this will be used in a loop.

      Maybe a misunderstanding, in the OP you were trying to localize package vars in a loop, this can't be done because of the loop scope.

      But of course you are free to initialize the vars in a loop or a list assign _after_ you localized them.

      Cheers Rolf