in reply to Reading the script code from itself

Thank you!

What I need is to get the list of defined constants to make their names exportable:

%EXPORT_TAGS = ( zaloopa => \@MM_zaloopa, herovina => \@MM_herovina, poeben => \@MM_poeben );
So, I want to make those constants exportable on demand. I just don't want to make lists for @MM_zaloopa, @MM_herovina and @MM_poeben by hands, as I don't want the constant name to be entered twice (once when I'm declaring the constant and twice when I'm adding the name to the list of exportable names). So I want this list to be made automatically, by the script itself. :)

Replies are listed 'Best First'.
Re^2: Reading the script code from itself (STASH introspection)
by LanX (Saint) on May 28, 2014 at 13:36 UTC
    Your use case is weird, instead of using constants I would choose hash (or array) elements right away from the beginning!

    Anyway your constants live in the STASH of your package and you seem to have a clear naming convention...

    ....so just grep {/^MM/} keys %YourPkg:: to find those symbols.

    Introspection is always better than parsing code!

    HTH! :)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

    update

    example:

    DB<110> $a=3 => 3 DB<111> grep /^a/,keys %main:: => ("a", "attributes::")