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

This will not generate the index that it is supposed to. Why?!
#!/usr/bin/perl open(FH, "indexfile") || die "Content-Type: text/html\n\n<h1>NOOOOOOO! +!!!!</h1>Error: $!"; print "Content-Type: text/html\n\n"; print "<html>\n<head>\n<title>Index</title>\n<body>\n<ul>\n"; foreach $page (<FH>) { ($id, $file, $title) = split /:/, $page; print "<li><a href=\"ipage.cgi?page=".$id."\" target=\"mframe\">".$ +title."</a></li>\n" } print "</ul>\n</body>\n</html>";

--linuxkid


imrunningoutofideas.co.cc

Replies are listed 'Best First'.
Re: CGI Help
by Ralesk (Pilgrim) on Mar 21, 2012 at 23:20 UTC
    print "<li><a href=\"ipage.cgi?page=".$id."\" target=\"mframe\">".$tit +le."</a></li>\n"

    While you are at it, you should read some of perlop or even perlintro — it’ll teach you a few things about qq (aka. ") and q (aka. ').

      I am familiar with qq, but i like using qoutes and backslash escapes

      --linuxkid


      imrunningoutofideas.co.cc

        You do realise that " can interpolate, right?

        I am familiar with qq, but i like using qoutes and backslash escapes

        Your fingers must hurt really really bad with the carpal tunnel from all the extraneous \backslashes you have to insert

        Or you only type 15min a day

Re: CGI Help
by roboticus (Chancellor) on Mar 21, 2012 at 19:09 UTC

    linuxkid:

    What's it doing wrong? What does the input data look like?

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      it will not output the list elements that i need it to, the input is id:file:title

      --linuxkid


      imrunningoutofideas.co.cc

        I just tried it out (on the console, as I don't have a web server set up):

        $ cat .index 17:floogle.bas:frabnicratz 18:zognarf.cpp:blofulous 1:Kweznerrific:Shabtabulae $ perl 960849.pl >t.html $ cat t.html Content-Type: text/html; charset=ISO-8859-1 <html> <head> <title>Index</title> <body> <ul> <li><a href="ipage.cgi?page=17" target="mframe">frabnicratz </a></li> <li><a href="ipage.cgi?page=18" target="mframe">blofulous </a></li> <li><a href="ipage.cgi?page=1" target="mframe">Shabtabulae </a></li> <li><a href="ipage.cgi?page= " target="mframe"></a></li> </ul> </body> </html>

        It looks reasonable, and when I open t.html in a browser, it looks like I would expect to see. Perhaps you've got incorrect permission settings on .index, and the file open is failing? You should always check the results of your file opens and verify that they work.

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

Re: CGI Help
by Anonymous Monk on Mar 22, 2012 at 08:21 UTC
    open(FH, "indexfile") || die "Content-Type: text/html\n\n<h1>NOOOOOOO!!!!!</h1>Error: $!";

    Dying prints to STDERR, CGI expects STDOUT. Your death will be printed into the web server's error log instead. Perhaps you mean:

    unless (open(FH, "<", "indexfile")) { print "Content-Type: text/html\n\n<h1>NOOOOOOO!!!!!</h1>Error: $!\n" +; exit(1); }

    BTW, I highly recommend using the text/plain content-type as long as you are debugging. It makes errors a lot more evident because web browsers try to "fix" a lot of bad HTML. (And you don't have to think of escaping HTML at that moment. Escaping is something you lack currently. It will lead to cross-site scripting vulnerabilities.)

      iis is funky, it sends that with the header, so i get that error in the browser.

      --linuxkid


      imrunningoutofideas.co.cc
Re: CGI Help
by Anonymous Monk on Mar 22, 2012 at 03:31 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.