Ouch, that tutorial does not look very good. Try this instead, and let me explain what it does:
#!c:\strawberry\perl\bin\perl.exe -T
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
my $host = 'localhost';
my $database = 'store';
my $tablename = 'inventory';
my $user = 'root';
my $pw = '';
my $dbh = DBI->connect("DBI:mysql:$database;host=$host",
$user, $pw, { RaiseError => 1 })
or die "Unable to open database: $DBI::errstr";
my $stmt = $dbh->prepare('SHOW DATABASES');
$stmt->execute();
my $databases = $stmt->fetchall_arrayref();
$dbh->disconnect();
my $page = new CGI;
print $page->header();
print $page->start_html();
foreach $database (@$databases) {
print $database->[0] . '<br />';
}
print $page->end_html();
The first line is a standard script header to let the web server know what binary to run. In this case, I added the '-T' flag to turn on taint mode in Perl. This will help for security.
You did add 'use strict' and 'use warnings', very good. Get into the practice of always having these at the top of your scripts.
The next three use statements are libraries from CPAN that will be included in this script. In this case I've used CGI for HTML generation, CGI::Carp for outputing error messages to the browser (this can help with debugging), and DBI for using databases. If you ever get the error message you've posted ('Can't locate ...') then that means you're trying to use a library that you haven't installed from CPAN yet. You can look at this document to get help on installing libraries.
Next I setup local variables. Since I've turned on strict mode above, every new variable must be prefixed by 'my' or 'our', depending on the scope that I want.
Now I connect to the database using the DBI module. Here I'm using the mysql library, so make sure that DBD::mysql is installed. I've also passed an optional parameter called 'RaiseError'; this will ensure that any SQL errors will cause an error. If I did not turn this on I would have to check the return variable for any SQL call I made. I've also decided to terminate the script using the 'die' operation if there is any issues with connecting. You may want to change this to a redirect for production; anything after the 'or' keyword will be executed on errors.
Then I perform my actual SQL operations. Using my database handle, I prepare a statement and execute it. I then retreive all of my results into a array reference for later use. Then I disconnect from the database.
The last block actually prints out the HTML. I create a new CGI object, then print out the header. I start the HTML, and then print out each database found. In the foreach statement, I need to let Perl know that $databases is actually an array reference, so I include the @ symbol before the variable. Then, since each row is another array reference, I get the first column using the '->[0]' operator. Finally I finish off the HTML.