Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: 'local' for imported variables doesn't work as expected (updates 1)

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


in reply to 'local' for imported variables doesn't work as expected

TIMTOWTDI

instead of exporting the variable you can just check it directly in the caller's namespace. (If it even exists )

use v5.12; use warnings; BEGIN{ package log; our $var= "default"; sub tst { my $pkg= (caller)[0]; no strict 'refs'; say ${"${pkg}::var"} } # export *Other::tst = \&tst; } package Other; our $var = __PACKAGE__; { local $var = "foo"; tst(); } tst();

foo Other
This might give your debugging interesting options...

Update

An alternative to messing with strict refs is to explicitly dig thru the stashes...

say ${$::{"${pkg}::"}{"var"}};

... Tho beauty is in the eye of the beholder ;)

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2025-11-12 03:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (68 votes). Check out past polls.

    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.