Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > cgi question

Reply
Thread Tools

cgi question

 
 
Bryan Williams
Guest
Posts: n/a
 
      11-08-2004
Hello All --

This is probably OT, but I hope someone here can tell me what I am
doing wrong.
I am trying to update some old Perl cgi scripts. The following html
generation works fine in Firefox, but returns a blank screen in IE
...... any clues why?

Thnx,

Bryan


#!/usr/bin/perl

print "Content-Type: text/html\n\n";

&print_part1;
&get_appts;
&print_part2;

sub get_appts {

# SNIP
# Database query here ....
# /SNIP

dumpresults();
}

sub print_part1 {
print <<ENDHTML;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><title>Appointment List</title>
<meta name="robots" content="noindex,nofollow">
<meta http-equiv="Pragma" content="no-cache">
</head>
<body text="#000000" link="#0000FF" vlink="#0000FF"
alink="#FF0000">
<center>
<!-- CONTENT TABLE -->
<table border="0" cellpadding="0" cellspacing="0">
<tr>

<table border=0 cellspacing=1 cellpadding=1>

<tr>
<td bgcolor="#CCCCCC" width=32><font size=1 face="ms sans
serif"><b><a href=/cgi-bin/appt_list.cgi?Time>Time</a></b></font></td>
<td bgcolor="#CCCCCC" width=130><font size=1 face="ms sans
serif"><b><a href=/cgi-bin/appt_list.cgi?Cust>Customer</a></b></font></td>
<td bgcolor="#CCCCCC" width=15><font size=1 face="ms sans
serif"><b>&nbsp;</b></font></td>
</tr>

ENDHTML
}


sub print_part2 {
print <<ENDHTML;

</table>
</td></tr></table>


<!-- /PAGE CONTENT -->
</td>
<td bgcolor="#CCCCCC" width=1><img src="/images/spacer.gif" height=1
width=1 border=0 alt=""></td>
<td bgcolor="#FFFFFF" width=1><img src="/images/spacer.gif" height=1
width=1 border=0 alt=""></td>
<td><center><a href="javascript:history.go(-1);"><img
src="/images/green_arrow1.gif" border=0 alt="Back"></a>&nbsp;<a
href="javascript:history.go(-1);"><img src="/images/green_arrow2.gif"
border=0 alt="Forward"></a></center></td>
<td bgcolor="#FFFFFF" width=2><img src="/images/spacer.gif" height=1
width=1 border=0 alt=""></td>
</tr>
</table>


<!-- FOOTER TABLE -->
</td>
</tr>
</table>

</center>
</body>
</html>

ENDHTML
}

sub dumpresults {
print <<ENDDATADUMP;

<tr>
<td bgcolor="#EEEEEE" align="left"><font face="ms sans serif"
size=1>&nbsp;$vStartTime</font></td>
<td bgcolor="#EEEEEE" align="left"><font face="ms sans serif"
size=1>&nbsp;$vCustLastName, $vCustFirstName</font></td>
<td bgcolor="#EEEEEE"><font face="ms sans serif" size=1>&nbsp;<a
href=/cgi-bin/reception.cgi?$vItemNo><img
src="/images/green_arrow2.gif" border="0"></a></font></td>
</tr>

ENDDATADUMP
}
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-08-2004
Bryan Williams wrote:
> This is probably OT,


Yes, it is. You obviously have an HTML problem, and this group discusses
Perl programming.

> but I hope someone here can tell me what I am
> doing wrong.


You'd have a better reason to be hopeful if you had asked in a group
that deals with HTML.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Eric Schwartz
Guest
Posts: n/a
 
      11-08-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Bryan Williams) writes:
> This is probably OT, but I hope someone here can tell me what I am
> doing wrong.


Several things. I don't know if any of them have to do with your
problem, but I find that fixing such things makes your life easier in
other ways, and who knows, it may even solve your problem! In any
event, your problem with IE is most likely to do with the HTML you're
printing out. Try asking about that question in a group that
discusses HTML problems. But since this is comp.lang.perl.misc, I'll
discuss a few things that come to mind about your Perl program below:

> #!/usr/bin/perl


use warnings;
use strict;

You probably want to

use CGI;

as well-- it handles a number of corner cases that, judging by the
code I see here, you probably aren't handling on your own.

> print "Content-Type: text/html\n\n";


If you did use CGI.pm, you could just:

print header;

> &print_part1;
> &get_appts;
> &print_part2;


As a general rule, your reaction to seeing & in front of function
calls should be "NO! DON'T DO THAT! WHERE'D YOU LEARN THAT? STOP
DOING THAT!". c.f. http://www.angryflower.com/bobsqu.gif for more
along thsoe lines.

Using & in front of function calls hasn't been necessary since, what,
perl4, I think? Certainly it hasn't been needed since the beginning
of this century. It also has several possibly unintended
side-effects, as seen in "perldoc -q '&foo'". (Quotes around &foo are
probably necessary, depending on your OS and shell.)

> sub get_appts {
>
> # SNIP
> # Database query here ....
> # /SNIP
>
> dumpresults();


Hrm, apparently you knew that. Why didn't you call the functions
above without the '&' then? Also, I notice you use several globals
inside dumpresults(); as a matter of style, you probably ought to pass
them in as parameters.

> }
>
> sub print_part1 {
> print <<ENDHTML;


<snip HTML>

> ENDHTML
> }


I know it's completely irrelevant to your problem at hand, but have
you looked at templating modules, such as Template Toolkit,
HTML::Mason, and the like? It might make your life much happier,
HMTL-generation-wise. I know it has mine.

> sub print_part2 {
> print <<ENDHTML;


<snip more HTML>

> ENDHTML
> }
>
> sub dumpresults {


my ($vStartTime, $vCustFirstName, $vCustLastName, $vItemNo) = @_;

and then you can call it as

dumpresults($vStartTime, $vCustFirstName, $vCustLastName, $vItemNo);

which is not only more helpful as documentation, but also means you
use fewer global variables, which is always a good thing.

> print <<ENDDATADUMP;


<snip HTML again>

> ENDDATADUMP
> }


I hope you get some help on your HTML problem elsewhere; perhaps
comp.infosystems.www.authoring.html might be of more use to you in
that regard. Here, alas, we discuss Perl.

-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
 
Reply With Quote
 
Alan J. Flavell
Guest
Posts: n/a
 
      11-08-2004
On Mon, 8 Nov 2004, Bryan Williams wrote:

> This is probably OT,


What would stand you in good stead, with problems of this nature,
would be to give some attention to the partitioning of your problem
space.

If you're having trouble with the (supposedly)-HTML extruded by some
executable code, then for heaven's sake grab a copy of that extruded
stuff and look at it more closely - get the executable program out of
the way - and ask the question (if there's still one to ask, once
you've looked at the extrusion) in a place where HTML and browsers are
on-topic.

Once you know what HTML you want/need to do that job, we can discuss
the details of how to write the program that's meant to produce it.

Specific hint: feed that extrusion to an HTML validator, e.g the one
at the W3C.

> I am trying to update some old Perl cgi scripts.


I've got some scripts that look little better than that, written in
the mid-1990s: I wouldn't care to expose them here, and when they come
up for any kind of "updating" I've resolved to do what I'm about to
suggest to you. It rather looks as if you'd be better off to
re-engineer them, in the sense of tossing out the old junk, reviewing
what's needing to be done, and writing a new one from scratch to do
it, using recent Perl techniques.

Others have already commented on some of those details. But I can't
resist repeating that the clue to solving complex problems is to
partition them into reasonably self-contained parts, and seek advice
(where the act of partitioning the problem hasn't already exposed the
clue, which I find myself is often the case) with each part, in the
place where that part is on-topic.

If you haven't noticed that this group collectively doesn't welcome
questions that are basically about CGI, or HTML, and only incidentally
involve Perl, then maybe you haven't been reading the group for long
enough to really get the benefit out of it that you could.

good luck.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick CGI question (specific to the CGI package) Ted Byers Perl Misc 19 11-30-2009 04:31 AM
(CGI-Target)Could not connect to CGI-Proxy John Smith Java 0 05-15-2006 09:21 PM
Python CGI - Accepting Input, Invoking Another Process, Ending CGI LarsenMTL Python 4 11-04-2004 05:59 PM
Calling cgi from cgi thru 'system' function. Different behaviour on browser v/s cmd line Shailan Perl 2 12-15-2003 04:26 PM
Re: CGI Perl "use CGI" statement fail Jürgen Exner Perl 0 07-31-2003 02:00 PM



Advertisments