Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Accessing module variables

by LanX (Saint)
on Apr 19, 2018 at 17:07 UTC ( [id://1213180]=note: print w/replies, xml ) Need Help??


in reply to Re: Accessing module variables
in thread Accessing module variables

Some code for introspection.

Used strict to demonstrate clean approaches

DB<80> package ABC::Foo; our $User='talexb'

> Well you could inspect the package stash(es) instead of using eval. *

DB<81> use strict;print ${ $main::{"ABC::"}{"Foo::"}{User} } talexb

> Another approach without eval is using symbolic refs, you need to locally no strict 'refs'; for that.

DB<82> use strict; no strict 'refs'; print ${ 'ABC::Foo::User' } talexb

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

*) NB: you could also avoid the main:: stash and hardcode

DB<99> use strict;print ${ $ABC::{"Foo::"}{User} } talexb

if ABC is static in your code.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found