#!/bin/perl use myClass; @childObjs = (); #---------------------------- sortNodes() ------------------------------------# sub sortNodes { printf("REF: %s / %s\n", ref($_[0]), ref($_[1])); # $_[0]->name() cmp $_[1]->name(); # $a->name() cmp $b->name(); 1 } #--- CREATING TREE OBJECT ----------------------------------------------------# $treeObj = new myClass("ROOT"); #--- CREATING CHILDS ! -------------------------------------------------------# for ( $idx=0; $idx<5; $idx++ ) { push(@childObjs, new myClass("CHILD_$idx")); } #--- ADD CHILDS ! ------------------------------------------------------------# $treeObj->addChild($childObjs[0], -1); $treeObj->addChild($childObjs[1], -1); $childObjs[1]->addChild($childObjs[2], -1); $treeObj->addChild($childObjs[3], 1); $childObjs[1]->addChild($childObjs[4], -1); #--- sort tree ! -------------------------------------------------------------# $treeObj->sort(\&sortNodes);