One problem is you aren't even tying $tree to begin with, you are tying %x, and then assigning the object ref to $tree. But I do not think there is any way to do this... nor should you really want to... root is very dscriptive or the top node of a tree (or bottom node bdepending on how you look at it)

You could probably do something along the lines of the followi ng...

use 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); }
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 ;-) TIMTOWTDI

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


In reply to Re: Is there any way to find the name of a tied variable? by suaveant
in thread Is there any way to find the name of a tied variable? by jryan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.