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"); }
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!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;
$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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |