NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
use peek_our as well (Score:1)
Re:use peek_our as well (Score:1)
#!/usr/bin/perl
use strict;
use warnings;
use PadWalker qw/peek_our peek_my/;
use Scalar::Util 'refaddr';
use Data::Dumper;
our $foo = 1;
our $bar = 2;
{
my $foo = 3;
print "my masks our\n", dumper(\$foo, \$bar);
}
print "now both are our\n", dumper(\$foo, \$bar);
sub dumper {
my $package = peek_our(1);
my $lexical = peek_my(1);
my %pad_vars;
while ( my ( $var, $ref ) = each %$package ) {
# we no longer remove the '$' sigil because we don't want
# "$foo = \@array" reported as "@foo".
$var =~ s/^[\@\%]/*/;
$pad_vars{ refaddr $ref } = $var;
}
while ( my ( $var, $ref ) = each %$lexical ) {
# we no longer remove the '$' sigil because we don't want
# "$foo = \@array" reported as "@foo".
$var =~ s/^[\@\%]/*/;
$pad_vars{ refaddr $ref } = $var;
}
my @names;
my $varcount = 1;
foreach (@_) {
my $name;
INNER: foreach ( \$_, $_ ) {
no warnings 'uninitialized';
$name = $pad_vars{ refaddr $_} and last INNER;
}
push @names, $name;
}
return Data::Dumper->Dump( \@_, \@names );
}
Reply to This
Parent
Re: (Score:1)
This seems to handle $" and the like:
#!/usr/bin/perl
use strict;
use warnings;
use PadWalker qw/peek_our peek_my/;
use Scalar::Util 'refaddr';
use Data::Dumper;
our $foo = 1;
our $bar = 2;
{
my $foo = 3;
print "my masks our\n", dumper(\$foo, \$bar, \$");
}
print "now both are our\n", dumper(\$foo, \$bar, \$");
sub dumper {
my $package = peek_our(1);
my $lexical = peek_my(1);
my %p