#55 Fixes NiceSlice's overwriting of $_

closed-out-of-date
nobody
None
5
2010-08-13
2009-07-02
No

I stumbled upon an unexpected side-effect of using the autoloader, as demonstrated using the two attached .pdl files. To see the problem, run

Discussion

  • David Mertens

    David Mertens - 2009-07-02

    Patch to NiceSlice.pm for the immediate problem.

     
  • David Mertens

    David Mertens - 2009-07-02

    Simple test .pdl file, to be autoloaded, used by the driver script.

     
  • David Mertens

    David Mertens - 2009-07-02

    Driver script tha demonstrates the problem. See the firs comment for details.

     
  • David Mertens

    David Mertens - 2009-07-02

    Sorry about that stub. I was attempting to upload a file before finishing the statement and it thought I had said everything already!

    Here's the deal. Put test.pdl and testSub.pdl in your Autoloader directory. Then call test() from the perldl prompt. Somewhere in the output, you should get something about "sub testSub...", i.e. the contents of testSub.pdl! I'll let the code speak for itself; it's not terribly long or complicated. Notice that if you run it a second time, you won't have the contents of testSub.pdl printed.

    The upshot is that NiceSlice is using $_ without localizing it. Under these circumstances, it happens in the eval block in NiceSlice.pm that begins on line 386. The patch file adds a single line of code that localizes $_.

    However, as the second half of the test script shows, this problem happens WHENEVER a subroutine modifies $_ without localizing it, which seems to suggest that all library code needs to localize $_. :(

     
  • Chris Marshall

    Chris Marshall - 2010-08-13
    • status: open --> closed-out-of-date
     

Log in to post a comment.