If you want to be "tricky", you can pack a binary heap into a one-dimensional list:
my $heap = ['Root', 'Child1', 'Child2', 'Grandchild1', Grandchild2'];
See heapsort for a stereotypical use of binary heaps. They're not as general as n-ary trees (being strictly binary and left-balanced), but they might make an interesting example.
For further fun and games with low-level-hacking data structures, pack a binheap into a string, with either null-separated or fixed-width fields:
Again, this is almost gratuitously ugly, but might make a "fun" example.# "\0" is a null, right? my $ns_heap = "R\0C1\0C2\0GC1\0GC2\0"; my $fw_heap = "R\0\0C1\0C2\0GC1GC2";
--
F
o
x
t
r
o
t
U
n
i
f
o
r
m
Found a typo in this node? /msg me
% man 3 strfry
In reply to Re: How do "you" make a tree in perl
by FoxtrotUniform
in thread How do "you" make a tree in perl
by stvn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |