Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: local element of my() array????

by BrowserUk (Patriarch)
on Feb 18, 2003 at 23:27 UTC ( [id://236437]=note: print w/replies, xml ) Need Help??


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. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://236437]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-24 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found