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?

    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
    }
     
    Bryan Williams, Nov 8, 2004
    #1
    1. Advertising

  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
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Nov 8, 2004
    #2
    1. Advertising

  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 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.
     
    Eric Schwartz, Nov 8, 2004
    #3
  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
    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.
     
    Alan J. Flavell, Nov 8, 2004
    #4
    1. Advertising

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. Jürgen Exner

    Re: CGI Perl "use CGI" statement fail

    Jürgen Exner, Jul 31, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,480
    Jürgen Exner
    Jul 31, 2003
  2. Shailan
    Replies:
    2
    Views:
    1,069
    Shailan
    Dec 15, 2003
  3. John Smith
    Replies:
    0
    Views:
    3,162
    John Smith
    May 15, 2006
  4. LarsenMTL
    Replies:
    4
    Views:
    782
    Eric Walstad
    Nov 4, 2004
  5. Ted Byers
    Replies:
    19
    Views:
    694
    Ilya Zakharevich
    Nov 30, 2009
Loading...

Share This Page