Could someone help me with this task.

I have this code to use in HTML pages to call a Picture Gallery

<!-- Start Galeria. -->
<p align=center>
<table border=0 cellpadding=0 cellspacing=0 width=210><tr><td>
<SCRIPT
LANGUAGE="JavaScript"
SRC="http://postais.comunidades.net/cgi-bin/galeria.cgi?dim=210&t=_top">
</SCRIPT>
</td></tr></table>
</p>
<!-- End Galeria. -->


And I've develop the following code to generate a table on page.


#!/usr/bin/perl -w

##########################################################################################
#
# The following code works. I've tested. See it till you found a separator like this one.
#
##########################################################################################

use CGI;
use Mysql;

# Required Library
#############################################
require "common.lib";

# Output Variable
#############################################
my $code = "";
my $nocomments = 1;

# Get PostCard Display Dim and Target
#############################################
my $query = new CGI;

# Postcard Display With or Height
my $dim = $query->param("DIM");
if ($dim eq "") { $dim = "210"; }

# Postcard Target to URL
my $targetURL = $query->param("t");
if ($targetURL eq "") { $targetURL = "_blank"; }

# Get Random PostCard
#############################################

# Now we connect to the database
&DBConnect();

# Make the SQL query string PID
my $command = "select images.graphic_id, images.graphic_title, images.graphic_name, author.copyright, images.graphic_format, author.url from images left join author using (author_id)";

# Send the SQL query to the database, catch possible errors
my $sth = $dbh->query($command);
&CGIError("<h2>Erro Mysql!</h2><br><br>$command<br><br>$!<br>") unless (defined $sth);

my $totalImages = $sth->numrows;

if ($totalImages > 0){

# Initiate Random Function
srand(time);

# random image ID
my $PID = int(rand($totalImages));

# Skip images to match image choosen
if ($totalImages > 1) { $sth->dataseek($PID); }

# OK, now we get the data
my @arr = ($sth->fetchrow);

# Separate the data by field
($gid, $graphic_title, $graphic_name, $graphic_author, $graphic_format, $author_url) = @arr;

if ($graphic_title eq ""){ $graphic_title = "Unknown"; }
if ($graphic_author eq ""){ $graphic_author = "Timeless"; }

# Show thumbnails
my $showImg = "width=$dim";
if ($graphic_format eq 1){ $showImg = "height=$dim"; }

##########################################################################################
#
# Now here is where I get troubled. It wont outputs nothing
#
##########################################################################################


# Format data
#############################################
print "Content-type: application/x-javascriptnn";

# Return everything nicely formatted
#############################################

print "document.write("<center><table>")n";
print "document.write("<tr><td valign=top>")n";
print "document.write("<a href="$URLPath$CGIPath/$ComposeCGI?GID=$gid" Target="$targetURL" Title="$PCName" Alt="$PCName" OnMouseOver="window.status='Visite o $PCName';return true;" OnMouseOut="window.status='';">")n";
print "document.write("<img src="$PostCardsPath/$graphic_name" alt="Clique e envie um postal a um amigo ou amiga..." $showImg align="center" border=0>")n";
print "document.write("</a>n</td></tr>")n";
print "document.write("<tr><td valign=top>")n";
print "document.write("<font face="Arial, sans-serif" color="#408080"><small>")n";
print "document.write("<small>$graphic_title</small><br>")n";

print "document.write("<small>© $graphic_author</small></small></font>")n";
print "document.write("</td></tr>")n";
print "document.write("</table></center>")n";
}


# And finally close it
#############################################
exit;


Thaks in advance or any help.


------------------
Projecto EINet