I used to use Perl with flat database files because I thought it was the simplest and best way to go.  Then I discovered mySQL--this reads like a laundry detergent commercial.  Anyway, mySQL has worked out much better for me.  It does take a bit of an effort to get started, but it's not too bad with the proper books and some patience.  As for its performance compared to other databases, it ranks as high as Oracle these days, according to e-week.

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.

-Spenser

That's Spenser, with an "s" like the detective.


In reply to Re: Perl/CGI Performance for a Shopping Cart by Spenser
in thread Perl/CGI Performance for a Shopping Cart by Sasquire

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.