#!/usr/bin/perl use strict; use DBI; use vars qw ( $opt_h $opt_m $opt_o $opt_i ); use Getopt::Std; getopts('hi:o:m:'); print "You forgot to remove the exit statement at the top of the program\n"; exit; if($opt_h) { print < -o -m <"dbname|host|user|pwd"> Arguments: -h displays this help message -i input file (required) -o output file (required) -m MySQL login information in the form "dbname|host|user|password" (required) HELP exit; } my $errstring = ""; my ($dbname,$host,$user,$pwd); if($opt_m) { ($dbname,$host,$user,$pwd) = split(/\|/,$opt_m); if($dbname eq "" || $host eq "" || $user eq "" || $pwd eq "") { $errstring .= "You must supply complete MySQL login information (-m).\n"; } } else { $errstring .= "You must supply the MySQL login information (-m).\n"; } my $input_file; if($opt_i) { $input_file = $opt_i; } else { $errstring .= "Input file required (-i).\n"; } my $output_file; if($opt_o) { $output_file = $opt_o; } else { $errstring .= "Output file required (-o).\n"; } if($errstring ne "") { #there is commandline info missing print "ERROR - Missing information on the commandline (use -h for help):\n$errstring"; exit; } ############################################ my (@row); ############## DATABASE CODE my $dbh = DBI->connect("DBI:mysql:$dbname:$host",$user,$pwd) or die "Can't connect to database!\n"; my $query = "show tables"; my $sth = $dbh->prepare($query) or die "Can't prepare $query: " . $dbh->errstr . "\n"; $sth->execute or die "Can't execute query: " . $dbh->errstr . "\n"; while(@row = $sth->fetchrow_array) { print "@row\n"; } $dbh->disconnect; ############## TAB DELIMTED (TSV) TEXT CODE open(FILE,$input_file); open(OUT,">$output_file"); while() { chomp; @row = split(/\t/); print "@row\n"; } close(OUT); close(FILE); ############## exit(0);