Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

CGI.pm idiosyncrasy?

by dusk (Friar)
on May 30, 2001 at 07:21 UTC ( #84157=perlquestion: print w/replies, xml ) Need Help??

dusk has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I encountered a strange problem while writing a CGI script for a site I'm developing. Here's the scoop:

print header, start_html (-title => 'Welcome to 0.0.0.0!', Link ({-rel => 'stylesheet', type => 'text/css', href => + 'style.css'}), base ({-href => 'http://0.0.0.0/cgi-bin/dir/'}), ), body ({-vlink => 'black'})

The preceeding causes the proceeding:

Content-Type: text/html; charset=ISO-8859-1 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>T +he POSIX Network</title> </head><body <link href="style.css" rel="stylesheet" type="text/css" / +>="&lt;base href=&quot;http://skeptical.no-ip.com/cgi-bin/posixnet/&q +uot; /&gt;"><body vlink="black" />,

As you can see, it appears as the opening body tag is not being closed, and the tag delimters are converted into their counter-equivalent (whatever that means) [&lt;, &gt;, &quot;]

Any explanation of what is going on will be helpful.

Regards,
Dusk

Replies are listed 'Best First'.
Re: CGI.pm idiosyncrasy?
by Trimbach (Curate) on May 30, 2001 at 07:56 UTC
    The "base" and "vlink" tags both belong in the "start_html" method when you're using CGI.pm. There is no "body" function per se in CGI.pm, so by typing it the module is assuming you know what you're doing and pretends it's a valid tag. Your "body" function doesn't "enclose" anything, so CGI.pm makes the perfectly valid guess that "body" is a self-closing tag like "break " and puts the closing slash within the tag per XHTML 1.0 guidelines. You're getting similar problems with "base" which should also be an attribute of start_html, and not it's own function/method.

    Try this instead: (untested)

    print header, start_html (-title => 'Welcome to 0.0.0.0!', Link ({-rel => 'stylesheet', type => 'text/css', href => + 'style.css'}), base => 'http://0.0.0.0/cgi-bin/dir/', vlink => "Black");
    For more info check out the "start_html" docs in the CGI.pm POD.

    Gary Blackburn
    Trained Killer

Re: CGI.pm idiosyncrasy?
by Zaxo (Archbishop) on May 30, 2001 at 09:35 UTC
    <it>start_html({ ...</it>
    -head=>[Link({{-rel => 'stylesheet', type => 'text/css', href => 'style.css'}),],

    To distribute the -head key the usual ref convention of CGI.pm applies

    After Compline
    Zaxo

      Changing   body ({-vlink => 'black'}) to   body ({-vlink => 'black'}, '') will solve one of the remaining problems.
Re: CGI.pm idiosyncrasy?
by hackmare (Pilgrim) on May 30, 2001 at 16:49 UTC
    You have a misplaced body tag which is nonsensical in the start_html context Try this program (note that it doesnt send xhtml).

    (Tested on solaris with perl5.0503)

    Script:
    
    #!/usr/bin/perl
    use CGI;
    use strict;
    my $p = new CGI;
    print $p->header;
    print $p->start_html(-title=>'Welcome to 0.0.0.0!',
                         -author=>'ronan@hackmare.com',
                         -base=>{href => 'http://0.0.0.0/cgi-bin/dir/'},
                         -meta=>{'keywords'=>'pharoah secret mummy',
                                   'copyright'=>'Hackmarish Things Happening'},
                         -style=>{'src'=>'/styles/style1.css'},
    		     -dtd=>1,
                         -BGCOLOR=>'blue',
    		     -vlink => 'black');
    print $p->p('Is this what you want?');
    print $p->end_html;
    

    Returns:
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    <HTML><HEAD><TITLE>Welcome to 0.0.0.0!</TITLE>
    <LINK REV=MADE HREF="mailto:ronan%40hackmare.com">
    <BASE HREF="http://localhost/perlmonk.pl">
    <META NAME="keywords" CONTENT="pharoah secret mummy">
    <META NAME="copyright" CONTENT="Hackmarish Things Happening">
    <LINK REL="stylesheet" HREF="/styles/style1.css">
    </HEAD><BODY BGCOLOR="blue" VLINK="black"><P>Is this what you want?</P></BODY></HTML>
    

    This code was adapted from the CGI.pm html POD
    --hackmare

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://84157]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2021-12-04 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (30 votes). Check out past polls.

    Notices?