cgi question

Discussion in 'Perl Misc' started by Bryan Williams, Nov 8, 2004.

  1. 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?




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


    sub get_appts {

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


    sub print_part1 {
    print <<ENDHTML;

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

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

    <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


    sub print_part2 {
    print <<ENDHTML;


    <!-- /PAGE CONTENT -->
    <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>

    <!-- FOOTER TABLE -->



    sub dumpresults {
    print <<ENDDATADUMP;

    <td bgcolor="#EEEEEE" align="left"><font face="ms sans serif"
    <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
    src="/images/green_arrow2.gif" border="0"></a></font></td>

    Bryan Williams, Nov 8, 2004
    1. Advertisements

  2. 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
    Gunnar Hjalmarsson, Nov 8, 2004
    1. Advertisements

  3. (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, 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. 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>

    > }

    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>

    > }
    > 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>

    > }

    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.

    Come to think of it, there are already a million monkeys on a million
    typewriters, and Usenet is NOTHING like Shakespeare.
    -- Blair Houghton.
    Eric Schwartz, Nov 8, 2004
  4. 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

    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

    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.
    Alan J. Flavell, Nov 8, 2004
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shailan
    Dec 15, 2003
  2. John Smith
    John Smith
    May 15, 2006
  3. LarsenMTL
    Eric Walstad
    Nov 4, 2004
  4. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Michael Sparks
    Jul 30, 2005
  5. Amir  Michail

    cgi relay for python cgi script

    Amir Michail, Oct 4, 2005, in forum: Python
    Michael Ekstrand
    Oct 4, 2005
  6. Alfred Z. Newmane

    Re: [OT] Re: "use CGI " hangs "CGI time out "

    Alfred Z. Newmane, Jun 23, 2005, in forum: C Programming
    Stan R.
    Jun 24, 2005
  7. epsilon
    Gabriel Genellina
    Aug 22, 2007
  8. Ted Byers
    Ilya Zakharevich
    Nov 30, 2009