in reply to local element of my() array????

This demonstrates that your interpretation is correct...

#! perl -slw use strict; my @foo = 1..9; { local $foo[3] = 'modified'; print "@foo"; } print "@foo"; __END__ C:\test>temp 1 2 3 modified 5 6 7 8 9 1 2 3 4 5 6 7 8 9

...now what's the problem:).

It's really quite clever and very useful in a few situations.


Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Replies are listed 'Best First'.
Re: Re: local element of my() array????
by Anonymous Monk on Feb 19, 2003 at 16:24 UTC
    My only problem is a lack of full understanding. If I only sort of think I get it, I'll screw something up. :)

    For example, I can't say

    
      my @x;
      local @x;
    
    
    because local requires a package variable such as @::x to localize, and my @x isn't in any package, because it's lexical. But I *can* say
    
      my @x;
      local $x[0];
    
    
    What's going on there? I just need an explanation of the magic that's handling that, because otherwise I have no clue what's happening, and the world becomes a dark and mysterious place. :)