The Devel namespace has lots of modules you can use for this sort of thing. You can, however, get some information on your own from the symbol table. Here is a simple illustration of that sort of thing from the command line,

$ perl -e'BEGIN{@ns{keys %::} = ()}; $foo = "bar";@names = grep {!exis +ts $ns{$_}} keys %::; print "@names",$/' foo names $
The BEGIN block collects all the keys of %main:: which exist before other stashes are formed and uses them as keys in the %ns hash. That hash is used to eliminate the 'noise' leaving only the names you have defined since.

That could be carried further by checking names against properties by the likes of,

print "foo has: ", $_, $" for (grep {*foo{$_} qw/SCALAR ARRAY HASH CODE GLOB IO/;
The values may be examined by dereferencing. Again the command line,
$ perl -e'BEGIN{@ns{keys %::} = ()}; $foo = "bar";@names = grep {!exis +ts $ns{$_}} keys %::; print ${*foo{SCALAR}} ,$/' bar $
All this only addresses the symbol tables. Lexical variables are not accessible by this method.

After Compline,
Zaxo


In reply to Re: Listing all Constants and values by Zaxo
in thread Listing all Constants and values by gwhite

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.