I am trying to run a code snippet from the Advanced Perl Programming book for dumping the stash. This is without any additional packages from CPAN.
The package containing the stash related instructions is as follows:
package DUMPVAR;
sub dumpvar {
my ($packageName) = @_;
local (*alias);
*stash = *{"${packageName}::"};
$, = " ";
while (($varName, $globValue) = each %stash) {
print "\n $varName ===========================================\n";
*alias = $globValue;
if (defined ($alias)) {
print "\t \$$varName $alias \n";
}
if (@alias) {
print "\t \@$varName @alias \n";
}
if (keys %alias) {
print "\t \%$varName " , %alias, " \n";
}
};
};
1;
The calling code is
#!/usr/bin/perl
use strict;
use warnings;
use DUMPVAR;
package MyData;
my $x = 10;
my @y = (1,2,3);
my %z = (1,2,3,4,5,6);
my $z = 300;
DUMPVAR::dumpvar('MyData');
I get no output what so ever. what is the problem?