perlquestion
LanX
Hei Friends<P><P>
is there any better way to find the "our" name of a package variable other than searching thru all possibilities? <P><P>
And why can't I find $x? cause its an alias?<P><P>
<c>
use feature qw(say);
use PadWalker qw(var_name peek_our);
use Data::Dump qw(pp);
sub our_name {
my $varref=\shift;
my $h_our=peek_our(1);
while ( my ($name,$ref) = each %$h_our ) {
return $name if $ref == $varref;
}
return;
}
package test;
our $bar=10;
package main;
for our $x (1) {
say our_name($bar); # > $bar
say our_name($x); # > ''
}
</c><P><P>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-708738">
<p>Cheers Rolf
</div></div>