Transformed the shell script to perl, keeping only one connection open.

(This script works for external DBs and it is much faster than opening
a connection every time).
Merge pull request #3 from DrDub/master

Sure, why not