in reply to Is there any way to find the name of a tied variable?
You could probably do something along the lines of the followi ng...
Now, you will probably have to turn off strict and warnings inside the new()... but it will work (I sort of tested it) but it is probably a bad idea, and you should probably just either keep the same name for all, or have them pass it in. However, don't ever say you weren't enlightened to the dark corners of perl ;-) TIMTOWTDIuse Tie::HashTree qw(hash_to_tree); #my $tree = tie my %x, 'Tie::HashTree'; Tie::HashTree->new('tree'); sub new { my $pkg = shift; my($ppackage) = (caller)[0]; ${$ppackage.'::'.$_[0]} = tie %{$ppackage.'::'.$_[0]}, $pkg; } sub TIEHASH { my ($class, $self) = @_; $self->{level} = ""; $self->{name} = "top"; $self->{top} = {}; bless ($self, $class); }
Update BTW - the new func ties and saves to $tree and %tree in the package it was called from
- Ant
- Some of my best work - Fish Dinner
|
|---|