in reply to Accessing module variables

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

It would be faster but not necessarily clearer.

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

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

Replies are listed 'Best First'.
Re^2: Accessing module variables
by LanX (Saint) on Apr 19, 2018 at 17:07 UTC
    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.