Re: Variable dump
- From: "Sisyphus" <sisyphus1@xxxxxxxxxxxxxxxxx>
- Date: Mon, 30 Jul 2007 00:57:31 +1000
"Bill H" <bill@xxxxxxxxx> wrote in message news:1185710910.829375.64370@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Is there a way in perl to dump all the variables used and their
current values to a file without printing everyone of them
individually?
Closest I could find is PadWalker ( http://search.cpan.org/~robin/PadWalker-1.5/PadWalker.pm ).
It handles lexical variables, but not globals (afaict) :
--------------------------------
use PadWalker;
use warnings;
my $s = 'hello world';
my @array = (1, 3, 5);
our $t = 'hello again';
our @array2 = (5, 7, 9);
$h1 = PadWalker::peek_my(0);
%deref = %{$h1};
print "\n\"my\" variables\n";
for(keys(%deref)) {
print "$_ : $deref{$_} \n";
print "@{$deref{$_}} \n" if ref($deref{$_}) eq "ARRAY";
print ${$deref{$_}}, "\n" if ref($deref{$_}) eq "SCALAR";
}
print "\n\"our\" variables\n";
$h1 = PadWalker::peek_our(0);
%deref = %{$h1};
for(keys(%deref)) {
print "$_ : $deref{$_} \n";
print "@{$deref{$_}} \n" if ref($deref{$_}) eq "ARRAY";
print ${$deref{$_}}, "\n" if ref($deref{$_}) eq "SCALAR";
}
--------------------------------
Which outputs:
--------------------------------
"my" variables
@array : ARRAY(0xb54914)
1 3 5
$s : SCALAR(0xb54944)
hello world
"our" variables
$t : SCALAR(0x26aa184)
hello again
@array2 : ARRAY(0x2716884)
5 7 9
--------------------------------
Faik, there may well be something better.
Hope this helps.
Cheers,
Rob
.
- References:
- Variable dump
- From: Bill H
- Variable dump
- Prev by Date: Re: Variable dump
- Next by Date: Re: Variable dump
- Previous by thread: Re: Variable dump
- Next by thread: form script question
- Index(es):