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

Hello O' Wise Ones,

I'm trying to write a script to produce html pages from a user input or submission with the ability to rate. I
need to enter an ssi code in the html section of the script. I'm sure the solution is rather simple as I am a
complete Perl novice. Everything works except for the printing of the $id value.

Here is the line of code:

<!--#include virtual="/cgi-bin/rating/rate_display.cgi?java=yes&product=Name_of_Product&id=$id"-->

The $id is created and printed to a flat database file but I cannot get it to print in the html output page. I'm
sure I'm formatting it incorrectly or something. If it were an input from the html form field, it would
print fine so I probably have to convert this value somehow.

Any ideas?

Replies are listed 'Best First'.
Re: Just a simple task
by Theo (Priest) on Aug 08, 2003 at 19:21 UTC
    I'm not much of an expert on anything, but I have played around with SSI a bit. The problem may be that the server that is parsing the SSI commands has no idea where to look for the value of $id. What do you get back in the id variable to your cgi script?

    Here is a helpful tutorial on SSI in case you need it. (You may be an expert for all I know)

    The solution may lie in using JavaScript to fetch the data, or some other thinking-out-of-the-box approach.

    -ted-

Re: Just a simple task
by blue_cowdawg (Monsignor) on Aug 08, 2003 at 16:24 UTC

    What does the underlying .cgi code look like? I see your wonderful SSI but that don't tell the whole story.


    Peter @ Berghold . Net

    Sieze the cow! Bite the day!

    Nobody expects the Perl inquisition!

    Test the code? We don't need to test no stinkin' code!
    All code posted here is as is where is unless otherwise stated.

    Brewer of Belgian style Ales

      The $id generates fine from this sub:
      The SSI is near the bottom.

      ####################################### sub get_file_name { ####################################### $proc=$$; $newnum=time; $newnum=substr($newnum,4,5); $date=localtime(time); ($day, $month, $num, $time, $year) = split(/\s+/,$date); $month=~tr/A-Z/a-z/; $PREF = "$month$num-"; $id="$PREF$newnum$proc"; $FILE_NAME="$BASEDIR/$PREF$newnum$proc$EXT"; $URL_NAME="$BASEURL/$PREF$newnum$proc$EXT"; }

      This is the sub that produces the html output page:

      ####################################### sub poem_page { ####################################### $poembody =<<__END_OF_POEM_BODY__; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <title>$fields{'poem_title'} by $fields{'author_name'}</title> <link rel="stylesheet" type="text/css" href="/poems/poem_font.css" /> <SCRIPT LANGUAGE="JavaScript"> <!-- if(navigator.userAgent.indexOf("MSIE") != -1) document.writeln (''); else document.writeln ('<EMBED SRC="$BASEURL/$fields{'midifile'}" AUTOSTART +="true" HIDDEN="true" VOLUME="60%">'); //--> </SCRIPT> </head> <BGSOUND SRC="$BASEURL/$fields{'midifile'}"> $BODYTAG $params <CENTER> <P> <TABLE WIDTH=584 BGCOLOR=WHITE BACKGROUND="/IMAGES/2x2.gif" BORDER=0 C +ELLPADDING=0 CELLSPACING=0> <TR> <TD ALIGN=CENTER VALIGN=MIDDLE height="70" BACKGROUND="$BASEURL/theme +s/$fields{'theme'}/head_bg.jpg" class="$fields{'font_family'}_title"> $fields{'poem_title'} </TD> </TR> <TR> <TD ALIGN=CENTER VALIGN=TOP> <TABLE> <TR> <TD WIDTH="30" align="right">&nbsp;</TD> <TD ALIGN="justify" VALIGN="TOP" class="$fields{'font_family'}"><d +iv align="justify"> <BR> <PRE align="justify" class="$fields{'font_family'}">$fields{'poem_ +body'}</PRE> </div> </TD> <TD WIDTH="30" align="right">&nbsp;</TD> </TR> </TABLE> </TD> </TR> <TR> <TD ALIGN=LEFT VALIGN=MIDDLE> <TABLE> <TR> <TD WIDTH="250" align="right" height="50">&nbsp;</TD> <TD WIDTH="250" ALIGN="left" class="$fields{'font_family'}"> - $fields{'author_name'} </TD> </TR> </TABLE> </TD> </TR> <TR> <TD ALIGN="CENTER" VALIGN="BOTTOM"><font face="arial" size="1" color= +"#444444">Copyright &copy; 2003</font> <p> <!--#include virtual="/cgi-bin/rating/rate_display.cgi?java=yes&produc +t=Name_of_Product&id=$id"--> </TD> </TR> </TABLE> </CENTER> </BODY> </HTML> __END_OF_POEM_BODY__ }

      Any way to get that $id to print?

        Have you tried testing for the definedness (is that a word? :) of the $id variable at the time of printing? Perhaps it's not that Perl won't print it as much as it is there is nothing to print?

        I didn't see any scoping being done on any of your variables and I have no sense of what order you are calling the subs. My gut feeling is that $id is not defined when you are trying to print it.

        You could try invoking the following from the main body of your program:

        use vars qw @ $id @; my $id="";
        If I make the guess (rightfully I hope) that the sub get_file_name() is being called before the sub poem_page() then $id will have been set and will be considered "global" for a lack of better term and its value seen by poem_page();


        Peter @ Berghold . Net

        Sieze the cow! Bite the day!

        Nobody expects the Perl inquisition!

        Test the code? We don't need to test no stinkin' code!
        All code posted here is as is where is unless otherwise stated.

        Brewer of Belgian style Ales

        Call me crazy, but isn't the problem here that you can't render an SSI when printing from Perl? SSIs only work when they're in web pages served up by a web server.

        ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print