in reply to Perl/CGI Performance for a Shopping Cart
Regarding your concerns about exporting to delimited text files, that's a breeze with mySQL and Perl and the Perl DBI module. As with everything else with Perl, there are many ways of doing it, but below is a simple overview of an export program. This export program is assuming that you've already set up a database and table in mySQL, of course.
#!/usr/bin/perl -w use DBI; # Connect to the mySQL server and # get today's orders. my $dbh = DBI->connect("DBI:mysql:orders:localhost","user","passwd") || die "Could not connect:".DBI->errstr; my $sql_stmnt = "SELECT order_id, item_no, qty, price FROM orders WHERE order_date=CURRENT_DATE'"; my $sth = $dbh->prepare($sql_stmnt); $sth->execute(); while(@orders = $sth->fetchrow_array()) { $order_id = $orders[0]; $item_no = $orders[1]; $qty = $orders[2]; $price = $orders[3]; # Create record with bars as delimiters # and push record into array for exporting. $order = $order_id . "|" . $item_no . "|" . $qty . "|" . $price . " +\n"; push(@export, $order); } $sth->finish(); $dbh->disconnect(); # Now loop through array of orders # and save to text file. open(EXP, ">client-orders.txt") || die "Could not open export file: $!"; foreach(@export){ print EXP; } close(EXP);
This bit of code is a lot wordier than it needs to be and can be consolidated into few lines. However, when starting out I think its better to spread the code out to keep your sanity and to make learning and trouble-shooting easier.
-SpenserThat's Spenser, with an "s" like the detective.
|
---|