perl saves the day! (kind of a seabuscuit thing)

statico on 2004-04-27T04:07:16

One-half of the College (including faculty and grad students and entire labs) is about to move into the new building. Your job is to make sure a shiny new CAT-6 cable is plugged into the proper wall port so that they can unpack, plug their machine(s) in and go. This requires plugging the right-length cable into the right jack with the right VLAN, and then making notes if the VLAN has to be changed from the defaults in case, say, they have three Solaris machines instead of just one.

Most of the lab coordinators were nice and gave you a list of everyone in their new lab space and where they're going to be sitting, so you checked with them beforehand and determined what machines they have. Your only resources are your old host database and a static web page where people find out where they're going to move into. It's 3:00PM, you need to get out of there by 5:30PM and be back at the place at 8:00AM the next day to help everyone move in. What do you do?

Fear not, strong co-op, for thou art familiar with The Perl. You:

  1. ..load each record of your sturdy host database with only the fields IP address (which you can tell the VLAN by), room number (the old one) and hostname (for convenience) into an array of arrays using constants to gain an extra speed boost when searching
  2. ..fetch the static page with LWP::Simple and scrape the only the tables you want into an array using HTML::TableExtract
  3. ..create a new array of hashes to cross reference two data source to determine what machines were in the old office, sorted by new room number and omitting the labs you've already wired
  4. ..use the Template Toolkit to print out a nice report you can carry from room to room:
|--------+--------------------------------------------------+-----------------|
|  Room  |                       IPs                        |      Name       |
|--------+--------------------------------------------------+----------------|
|  238   |  192.18.218.107 (maxro.ccs.some.edu)             |  Joe Tenure     |
|        |  192.18.215.154 (zeg.ccs.some.edu)               |                 |
|--------+--------------------------------------------------+----------------|
|  ...   |  ...                                             | ...             |

You write the script in an hour and finish outfitting the offices. Well done!

(Actually, I never saw "Seabiscuit," but you get the idea.)