is there any better way to find the "our" name of a package variable other than searching thru all possibilities?
And why can't I find $x? cause its an alias?
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); # > '' }
Cheers Rolf
In reply to Inspecting the name of a variable by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |