- November 30th, 2005
- Write comment
In the midst of the non-stop action at work today (I was watching Return of the Jedi) I decided to move my old conversions.py script over to conversions.pl. My clumsy nature with python may well have been the cause of the overuse of
else – but in the end conversions.py lived as a 100+ line menu driven script.
That’s right, I said menu. You run the script, it pukes a menu with a host of options – do you want to go from kilowatts to horsepower? Make your selection, and then you get to input your value, and hit enter again. Rejoice, for now you have your new value, and new unit of measure! Awesome, only not really at all.
My issue with implementing any command-line mojo revolved around my inability (I strongly doubt this is python’s fault) to pass numerical values as numerical values through
sys.argv. Options, being strings, were not an issue – but for the life of me I could not manage to pass a number as an integer, just a string.
Enter perl, and
./conversions.pl fc 32 returns 0! All in 28 lines. The only reason it takes 28 lines is because I felt like using a seperate line for each key/value pair in the hash containing my conversion factors. Instead of a different
if statement for each individual possibility, I have one
if checking for the first command line argument, in my conversion factors hash. The best part is the ease with which I can make a CGI script out of this, and you’ll probably find that I do this shortly.