2008/12/17 Chas. Owens <chas.ow...@gmail.com>

> On Tue, Dec 16, 2008 at 10:30, Panda-X <exilepa...@gmail.com> wrote:
> > Hi Owen,
> >
> > 2008/12/15 Chas. Owens <chas.ow...@gmail.com>
> >>
> >> On Mon, Dec 15, 2008 at 04:18, Panda-X <exilepa...@gmail.com> wrote:
> >> > Hello,
> >> >
> >> > I have a hash tree, which sub- and sub-sub-sub ( and whatever )
> >> > items inside are all hashes.
> >> >
> >> > and the next step I dealing with this hash tree is to use
> >> > Data::Dumper to dump it out.
> >> >
> >> > What I hope that the Data::Dumper result can keep the order as
> >> > what I declared at very first. Is that anyway I can do this ?
> >> >
> >> > Thank you very much for any clues.
> >> >
> >> > Regards,
> >> > Panda-X
> >> >
> >>
> >> You can try Tie::IxHash*, but it does not transparently handle
> >> nesting.  If your hash has a predictable structure you could write
> >> your own version of Dumper that knows the right order.  You could also
> >> store an incrementing value with each entry.
> >>
> >> It is also possible that there is a better solution, but that is
> >> dependent on what you are trying to do.  Can you tell us what sort of
> >> data you are working with that the order of a hash (a fundamentally
> >> unordered data structure) matters?  If it is just that you want a
> >> predictable order to the output, set $Data::Dumper::Sortkeys to 1.
> >>
> >> * http://search.cpan.org/dist/Tie-IxHash/lib/Tie/IxHash.pm
> >
> > I am trying to deal with this structure, and this is using to ask Tk to
> > build the object :
> >
> > my $interface = {
> >   MW => {
> >      MENU_mn => { },
> >      NOTEBOOK_nb => {
> >          TAB_tab1 => {
> >              BUTTON_but1 => { },
> >              BUTTON_but2 => { },
> >           },
> >          TAB_tab2 => {
> >              FRAME_frmWhatever => {
> >                TEXT_someContext => { },
> >                BUTTON_save => { },
> >              },
> >          },
> >      },
> >   },
> > }
> >
> > But maybe I missed something inside, seems Tie::IxHash do not tie hash
> > tree...?
> > Am I correct ?
> snip
>
> Tie::IxHash is tied to the variable before you put stuff in and only
> has an effect on the key order of that hash, not hashes underneath it.
>
> Are you calling some specific Tk method to build the object tree, or
> are you doing that yourself?  If you are doing it yourself, then you
> probably want something like this instead:
>
>
> my $interface = [
>   { type => 'MW', name => 'mw', children => [
>      { type => 'MENU', name => 'mn' },
>      { type => 'NOTEBOOK', name => 'nb', children => [
>         { type => 'TAB', name => 'tab1', children => [
>            { type => 'BUTTON', name => 'but1', callback => \&button1 },
>            { type => 'BUTTON', name => 'but2', callback => \&button2 },
>         ]},
>         { type => 'TAB', name => 'tab2', children => [
>            { type => 'FRAME', name => 'frmWhatever', children => [
>               { type => 'TEXT', name => 'someContext' },
>               { type => 'BUTTON', name => 'save', callback => \&save }
>            ]}
>         ]}
>      ]}
>   ]}
> ];
>
> --
> Chas. Owens
> wonkden.net
> The most important skill a programmer can have is the ability to read.
>


O!! That works!!! Using array can keep the tree order, as well the struct!!
Thanks Owen! Thank you!

Panda-X

Reply via email to