I have been programming for several years, and have been exposed to all sorts of problems along the way. However, Friday was about my first opportunity to actually use a tree traversal in a ‘real’ project, not just one assigned by a professor.
As most *nix types are aware, you can set up an aliases file to map addresses onto real world users. The problem with this file is that aliases can get stale, new aliases can be made that end up totally encompassing old ones (unintentionally), etc.
So, the request came about to be able to use a webform to look up where, exactly, an alias points. So, into our work order ticketing system it went, and I started working on it on paper Thursday evening. Turns out that it is not in fact to be a graph problem but rather a tree problem. This is a Good Thing™. Graph problems aren’t horrible to work with, but they are substantially more complex than tree problems.
The general form of the /etc/aliases file is listed above, but I left out an important caveat - aliases can point to a file of delimited targets via the :include: directive. To make a medium-length story pretty short, to parse the aliases file, every line needs to be read, and then tokenized to display the results of a search, recursively.
I suppose you could traverse the tree using a loop-based approach, but heaven help you to handle the corner cases. The only I have to track in traversing the tree is what the most recently checked alias was, and advance to the next one in the list when the check on that iteration is over.
Overall, it turned out to be a really easy to write script, and it’s now live on our site. If you are Shodor staff, you can play with it here.
Posted by wmyers in work