Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: 'local' for imported variables doesn't work as expected (1 update)

by LanX (Saint)
on Oct 04, 2024 at 11:54 UTC ( [id://11162055]=note: print w/replies, xml ) Need Help??


in reply to Re: 'local' for imported variables doesn't work as expected (4 updates)
in thread 'local' for imported variables doesn't work as expected

Tl;Dr , but I don't think there is anything wrong with Exporter it's just the way local works. (See my other post which replicates the problem without Exporter)

It's localizing the symbol NOT the referenced variable.

Otherwise it would be possible to localize lexical variables too.

Update

Demo in the debugger

DB<13> my $x = 42; *b = \$x; {local $b= 666; say "$b = $x"}; say "$b = + $x" 666 = 42 42 = 42

Now exporting typeglobs works because the scalar slot is one level deeper, hence local will operate on the same slot

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

  • Comment on Re^2: 'local' for imported variables doesn't work as expected (1 update)
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2026-03-16 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.