PadWalker has some serious problems when it comes to file-level lexical variables. Consider the following Perl script and Perl module:
use strict; use Devel::Size qw(total_size); use Data::Dumper; use TestModule; my $h = TestModule::get_mem(); foreach my $name (keys(%$h)) { my $ref = $h->{$name}; my $mem = total_size($ref); print("$name - $mem bytes\n"); print(Dumper($ref)); print("\n"); }
package TestModule; use strict; use PadWalker qw(peek_my); my $str = 'abcxyzabcxyzabcxyzabcxyz'; my $h = { x => 'abcabcabcabcabc', y => 'xyzxyzxyzxyzxyz'}; my $l = ['abcdefghi', 'stuvwxyz']; sub get_mem { my $str1 = 'abcxyzabcxyzabcxyzabcxyz'; my $h1 = { x => 'abcabcabcabcabc', y => 'xyzxyzxyzxyzxyz'}; my $l1 = ['abcdefghi', 'stuvwxyz']; return peek_my(0); } 1;
It produces the following output (I'm doing this on Windows using ActivePerl, PadWalker version 2.2). I'm particularly intrigued by the fact that it reports the variable $str of having size 88 bytes (which is correct), while Data::Dumper says that it's a reference to undef!
$str1 - 52 bytes $VAR1 = \'abcxyzabcxyzabcxyzabcxyz'; $h - 16 bytes $VAR1 = \undef; $h1 - 230 bytes $VAR1 = \{ 'y' => 'xyzxyzxyzxyzxyz', 'x' => 'abcabcabcabcabc' }; $l1 - 132 bytes $VAR1 = \[ 'abcdefghi', 'stuvwxyz' ]; $str - 52 bytes $VAR1 = \undef; $l - 16 bytes $VAR1 = \undef;

In reply to Re^4: 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.