"be consistent" | |
PerlMonks |
Linked-list Style Data Structureby impossiblerobot (Deacon) |
on Oct 01, 2002 at 15:46 UTC ( [id://202030]=perlquestion: print w/replies, xml ) | Need Help?? |
impossiblerobot has asked for the wisdom of the Perl Monks concerning the following question: Again, I humbly approach the monastery ... In a wizard-style web application I've created, I use the following data structure to track navigation:
which allows me to say $navigation_map->{second_page}{NEXT} to find out what the next screen should be. Unfortunately, the same list of pages does not appear in each of the installations of this app, so constructing the navigation map and editing the links for each instance is a pain. What I should be able to do is use an array, so I can just do this:
So I created an object to build the hash structure for me (from an array):
I could then use it as:
Of course the next natural step was creating accessors so that I could say $navigation_map->next('second_page') instead of $navigation_map->{second_page}{NEXT}. I also created a "current page" pointer so I could use the class as an iterator. This solution seems to work well for my current usage, since I currently have no need to insert or delete entries (which would require building additional methods). However, my question (finally) is: What better (or alternate) ways would you suggest for implementing this functionality? Is there a generic solution I should be looking at? Impossible Robot
Back to
Seekers of Perl Wisdom
|
|