So, I don't want to be thick here, but here's my confusion. Take my baby example of a test.pl script and a TestModule.pm Perl module. What I'm interested in is in test.pl, finding the variables, declared using "my", that are at file level (i.e. outside of any function) in TestModule.pm. Now, being outside of any function in TestModule.pm, they are created when TestModule.pm is parsed. I've read somewhere that it's kind of like TestModule.pm is enclosed in '{' and '}'. I know from experience that these variables exist for the life of the script. So, it seems to me that the statement "Lexical variables are destroyed at the end of their scope." isn't relevant here, i.e. the "scope" of TestModule.pm doesn't end until the script test.pl ends.

I have gotten what I need by creating a function like this one in TestModule.pm and calling it from test.pl:

# --------------------------------------------------------- sub GetMyMemoryMap { # --- returns hash: # { <nameWSigil> => { # Shared => <is_shared>, # Size => <nBytes>, # }} require Devel::Size; require threads::shared; return { '$hUserInfo' => { Shared => threads::shared::is_shared($hUserInfo), Size => Devel::Size::total_size($hUserInfo), } }; } # GetMyMemoryMap() # ----------------------------------------------------------

and it works. But it isn't automatic. I.e. it would require me to create such a function, which has to explicitly know what file level lexical variables exist in each of my Perl modules (the actual application has many, many Perl modules)


In reply to Re^12: Finding file level lexical variables by johndeighan
in thread Finding file level lexical variables by johndeighan

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.