APM: Running a perl prog from a perl prog?

Wayne Walker wwalker at bybent.com
Tue Oct 17 17:14:14 PDT 2006


http://www.bybent.com/cn.tar.gz contains 3 files.  Yours, a slightly
revised version of yours, and a more revised version of yours.

I think they will simplify your use of DBI and perl.

Wayne

(Also attaching to here, but not sure if the list allows attachments.

On Tue, Oct 17, 2006 at 06:26:24PM -0500, CaptNemo wrote:
> What I'm trying to do is write a web prog so that people can search a 
> database and easily pull the info.
> 
> I HATE dealing with DBI so I wanted to make the database stuff modular. I 
> want the main prog to handle the cgi stuff and call smaller progs to do the 
> database stuff.  That way I can re-use the modules to make more progs.
> 
> HERE'S MY FIRST MODULE:
> 
> dbquery.pl
> --------------------------------------------------------------------------------
> #!/usr/bin/perl -wT
> use DBI;
> use strict;
> 
> my $dbdriver = $ARGV[0];
> my $db = $ARGV[1];
> my $dbuser = $ARGV[2];
> my $dbpasswd = $ARGV[3];
> my $dbtable = $ARGV[4];
> my $condition = $ARGV[5];
> 
> my @row_array;
> 
> if ( $#ARGV ==5 ) {
> 
> 		my $dbh = DBI->connect( "DBI:$dbdriver:$db",$dbuser,$dbpasswd,)
> 			|| die "Database connection not made: $DBI::errstr";
> 		
> 		my $sth = $dbh->prepare("SELECT * FROM $dbtable WHERE $condition")
> 			or die $dbh->errstr;
> 		$sth->execute() or die $dbh->errstr;
> 		
> 		while (my @row_array = $sth->fetchrow_array) {
> 			print "$row_array[0], $row_array[1], $row_array[2] \n";
> 			}
> 		$dbh->disconnect();
> 	}
> 	elsif ( $#ARGV <= 4 ) {
> 		print "\n-----------------------------ERROR------------------------------\n";
> 		print "NOT ENOUGH ARGUMENTS\n";
> 		print "dbquery.pl usage: dbquery.pl DBDRIVER DB DBUSER DBPASSWORD DBTABLE 
> \"CONDITION\"\n";
> 		print "NOTE: DBDIVER is usually \"mysql\" but it can be other things like 
> \"oracle\".\n";
> 		print "      EXAMPLE: dbquery.pl mysql databas...\n";
> 		print "NOTE: The total CONDITION must be in quotes with the matching data 
> in single quotes. \n";
> 		print "      EXAMPLE: \"product LIKE 'bicycle'\"\n";
> 		print "---------------------------END ERROR----------------------------\n\n";
> 	}
> 	else {
> 		print "\n-----------------------------ERROR------------------------------\n";
> 		print "TOO MANY ARGUMENTS\n";
> 		print "dbquery.pl usage: dbquery.pl DBDRIVER DB DBUSER DBPASSWORD DBTABLE 
> \"CONDITION\"\n";
> 		print "NOTE: DBDIVER is usually \"mysql\" but it can be other things like 
> \"oracle\".\n";
> 		print "      EXAMPLE: dbquery.pl mysql databas...\n";
> 		print "NOTE: The total CONDITION must be in quotes with the matching data 
> in single quotes. \n";
> 		print "      EXAMPLE: \"product LIKE 'bicycle'\"\n";
> 		print "---------------------------END ERROR----------------------------\n\n";
> 	}
> 
> 
> It queries a database and returns the first 3 records of matches.
> 
> _______________________________________________
> Austin mailing list
> Austin at pm.org
> http://mail.pm.org/mailman/listinfo/austin

-- 

Wayne Walker

www.unwiredbuyer.com - when you just can't be by the computer

wwalker at bybent.com                    Do you use Linux?!
http://www.bybent.com                 Get Counted!  http://counter.li.org/
Perl - http://www.perl.org/           Perl User Groups - http://www.pm.org/
Jabber:  wwalker at jabber.gnumber.com   AIM:     lwwalkerbybent
IRC:     wwalker on freenode.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cn.tar.gz
Type: application/x-tar-gz
Size: 1083 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/austin/attachments/20061017/2b0c010f/attachment.bin 


More information about the Austin mailing list