Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display perl in webpage

Status
Not open for further replies.

johnv20

Programmer
Sep 26, 2001
292
US
Hi,
I normally use perl for standalone apps & javascript asp for web apps so could someone please explain to me why the code below is not displaying any info when I try to run it as either an asp or a htm

Also is there a method such as the response.expires available in perl ( not cgi ) where I can clear all cached info instead of having to unset every variable I use

<%@ Language=PerlScript%>
<html><body>
<%
use Win32::ODBC;
$dsm=undef;
$dsm=&quot;DSN=EMF3BRM2;UID=serverweb;PWD=&quot;;
$db = new Win32::ODBC($dsm);
@array1=();
if ($db)
{
$db->Sql(&quot; Select * from Family &quot;);

while($db->FetchRow())
{
undef %Data;
%Data = $db->DataHash();
$Name = &quot;$Data{FamilyID}&quot;;
print &quot;$Name&quot;;

}
}
$db->Close();
 
HTML doesn't know where the script is and what it's supposed to do with it. Perl scripts are server side and must be run from the cgi-bin directory.

Render your page in Perl, calling the database functions from your script. There's always a better way...
 
Thanks tviman - but what exactly do you mean by render ?
 
Your perl script will &quot;render&quot;, or &quot;display&quot; a web page. There's always a better way...
 
When you run a cgi script, the standard out of the script is sent to the web browser. Web browsers need to know the type of data they are receiving so it knows how to display it. The first thing the script needs to print is the mime-type, then whatever information to be displayed. Kind of like this:
Code:
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<html><head><title>foo</title></html>&quot;;

# or more commonly

print <<END;
Content-type: text/html

<html>
<head><title>foo</title>
</html>
END
----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top