For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2007 > Most Appropriate Data Structure









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Most Appropriate Data Structure
Pat McDonnell

2007-08-25, 7:00 pm

Hello -

I'm working on a script in which the user provides a path, and the script
does something based on that path. I want to develop some type of
association between paths, and actions to perform. For instance, take the
following:

Path Action
----------------------
/home &home()
/home/luser &luser()
/home/luser/abc &luserabc();

So, if the user passes /home/luser, &luser would be executed. If the user
passes /home/luser/xyz, &luser would still be executed, as it is the most
specific match for that path. If /home/anotheruser is passed, &home would
be executed, as that is the most specific match. Does this make sense?

So, my question is, is there any type of data structure/module that is best
for this? I could hack something together with regex's and loops easily
enough, but I was hoping there would be something "cleaner." I've looked
at a trie, but that seems to be the opposite of what I want. Thanks.

--
Posted via a free Usenet account from http://www.teranews.com

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com