I wish I could claim that I came up with the "build it in reverse" technique myself. I saw it first in a great book published by O'Reilly & Associates, "Mastering Algorithms with Perl". The book discusses (among many other topics) building linked lists, and one method is surprisingly similar to the solution I provided to your problem. Your situation was a little different, but being familiar with the Algorithms book provided me with the basic concept. I highly recommend the book.
You can also learn a great deal about complex datastructures and Perl's references from the following POD's:
- perlreftut - Tutorial on references.
- perllol - Tutorial on building and manipulating lists of lists, and other similar datastructures using references.
- perldsc - Perl Datastructure Cookbook... good stuff.
- perlref - Of course, the definitive source.
Happy hunting...
| [reply] |