I'm thinking about writing some training material examining the development of a short but real world shell script. By the time the script is completed, it becomes obvious that the shell is good for simple problems but eventually one should consider a less quirky language. I'm toying with the idea of including a translation of the script to Perl, Python and Ruby.
The target audience is system administrators, possibly with no previous programming experience. I want the scripts to use the same algorithm as the shell script, be readable by a newbie, but also capture the flavor of each language. Because I consider myself a jack of all languages, master of none, I'd appreciate if you took a moment to check my translation to your favorite language and let me know if I've done anything offensive.
spellcheck.pl
Description: Perl program
#!/usr/bin/python
import os
from os.path import abspath, dirname, exists
import re
import sys
DIR = abspath( dirname( dirname( __file__ ) ) )
DICT = abspath( DIR+'/doc/aspell.en.pws' )
def spellcheck( file ):
print "Spell checking %s" % file
cmd = "aspell -H -p '%s' -c '%s'" % (DICT, file)
os.system( cmd )
argv = sys.argv[1:]
argc = len( argv )
if (argc == 0) or ((argc == 1) and not exists(argv[0])):
if argc == 0:
cmd = "git diff --name-only 'master'"
else:
cmd = "git diff --name-only '%s'" % argv[0]
filter = re.compile( '.*/.*\.xml$', re.M )
files = os.popen( cmd ).read()
for file in filter.findall( files ):
spellcheck( file )
else:
for file in sys.argv[1:]:
spellcheck( file )
spellcheck.rb
Description: application/ruby
spellcheckIFS.sh
Description: application/shellscript
/* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
