use DBI; $username = "YOUR_USER_NAME"; $password = "YOUR_PASSWORD"; $filename = $ARGV[0]; if($#ARGV == 0) { $problemnumber = -1; $numrowprinted = 5; print "Will attempt to execute all queries\n\n"; print "============================================================================================================================================\n"; } else { $problemnumber = $ARGV[1]; $numrowprinted = -1; print "Will attempt to execute query number $problemnumber\n\n"; print "============================================================================================================================================\n"; } open(FILEIN, "< $ARGV[0]"); $dbh=DBI->connect("dbi:Oracle:host=ginger.umd.edu;sid=dbclass2;port=1521","$username","$password",{AutoCommit=>0}) or die "Can't log in: $!"; @dontexecute = (1, 2, 15, 21, 22); while() { if(/=== ([0-9][0-9]*)/) { if(($problemnumber == -1) || ($1 == $problemnumber)) { print "=== Found solution $1\n"; if(grep /^$1$/, @dontexecute) { print "Can't execute solution number $1 using this script\n"; } else { $command = ""; $_ = ; while(!/---/) { print; chomp; $command = "$command $_" if !/^\#/; $_ = ; } @subcommands = split(/;/, $command); for(@subcommands) { if(!/^ *$/) { # try not to execute commands with just white spaces print "\n"; $sth = $dbh->prepare($_) or print "$DBI::errstr"; $sth->execute or print "Can't execute sth: $DBI::errstr."; if($sth->{NUM_OF_FIELDS} > 0) { print "**************** RESULT *********************\n"; $count = 0; while ((@myrow)=$sth->fetchrow_array) { if (($numrowprinted == -1) || ($count < $numrowprinted)) { print "@myrow\n" if defined @myrow; $count++; } } print "*********************************************\n"; } $sth->finish; } print "============================================================================================================================================\n"; } } } } } $dbh->disconnect;