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)
Reply to This
Re: (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
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
Re: (Score:1)
This works for vars.pm and $Fully::Qualified::Variables too?
Re: (Score:1)
Yes, but only if they have had a value assigned to them. Otherwise they aren't really variables yet (just compiler directives to not throw errors if it sees them).
Re: (Score:1)
Well, it handles $main::foo, but not $other::package::foo. You would need to look in %other::package for it. Hmm, there should be some way of finding out what namespaces exist.
Re: (Score:1)
Alright, it is ugly, but it gets the job done. This handles everything but var pragma variables that have never been assigned to (they don't really exist yet). This version also has the benefit of displaying package and lexical variables differently, so you can easily spot the masking effect. Hmm, but I think there might be a bug in the case where you have
{
our $foo;
{
my $foo;
Re: (Score:1)
I take it back, since he is using the address of the variable as the key it works fine, and there is the order doesn't matter when you build the hash.