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

I keep trying to execute this file on my web site, but I keep getting a blank screen. Here's the lowdown: The information is gathered from the variable $value, which gets its information from the name "video". I then use the $value variable to open up the specific file, since the info for the file is in the variable. Lower in the application, it takes all of the information from the file and displays it in the proper spot with the HTML.
#!/usr/bin/perl # Loads the CGI Module use CGI; # creates a new CGI object my $page = new CGI; # This will print a standard HTML header print $page->header; # Grab a named CGI parameter my $value = $page->param(video); #Open up the file that contains the review of the video open(SEE, "../$value"); #Save it to an array @video_info = <SEE>; #Now print out lots of HyperText Mark-up Language <<HTMLSTUFF; <HTML> <HEAD> <META NAME="GENERATOR" CONTENT="Adobe PageMill 3.0 Win"> <TITLE>Animetion Station &gt; Video Review &gt; Oh MY Goddess! Volum +e 1</title> <LINK REL="stylesheet" HREF="../Style.css" TYPE="text/css"> </head> <BODY TEXT="#ffffff"> <P STYLE="background-color: #3257b8; width: 350px;"><I><FONT SIZE="+3" FACE="Garamond">Animetion Station</font></i></p> <div id="Bottom"> <P><I><FONT SIZE="+2" FACE="Garamond">Video Review</font></i></p> </div> <P><CENTER>&nbsp;</center></p> <P><TABLE WIDTH="738" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="24"> <TR> <TD WIDTH="67" VALIGN="TOP"> <div class="Standard"> <P><CENTER><A HREF="../index.htm">[Home]</a> <HR> <A HREF="../Gallery.shtml">[Gallery]</a> <HR> <A HREF="../Manga.shtml">[Manga]</a> <HR> <A HREF="../Video_Review.shtml">[Video Reviews]</a> <HR> <A HREF="../Links.shtml">[Links]</a> <HR> <A HREF="../Web_Comic.shtml">[Web Comic]</a></center></td> <TD VALIGN="TOP" WIDTH="270" HEIGHT="131"> </div> </td> <TD WIDTH="382" VALIGN="TOP"> @video_info <!--VIDEO REVIEW LINKS--> <P STYLE="background-color: darkBlue;"> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fBattle_Skip +per_Vol_1.txt">Battle Skipper Volume One by Ertain</a><BR> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fOMG_Vol_1.t +xt">Oh My Goddess! Volume One by Ertain</a><BR> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fOMG_Vol_2.t +xt">Oh My Goddess! Volume Two by Ertain</a><BR> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fOMG_Vol_3.t +xt">Oh My Goddess! Volune Three by Ertain</a><BR> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fOMG_Vol_4.t +xt">Oh My Goddess! Volume Four by Ertain</a><BR> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fOMG_Vol_5.t +xt">Oh My Goddess! Volume Five by Ertain</a></p> </td> </tr> </table> </body> </html> HTMLSTUFF #close file close(SEE);

Replies are listed 'Best First'.
Re: Display Troubles
by premchai21 (Curate) on Oct 08, 2001 at 22:39 UTC
    You're not printing the HTMLSTUFF. You're doing a heredoc in void context, which takes the string and does nothing with it. Try print <<HTMLSTUFF. There are a couple of other ways this could be improved, too -- use CGI methods for generating the HTMLSTUFF, for instance.
Re: Display Troubles
by thatguy (Parson) on Oct 08, 2001 at 23:10 UTC
    It would probably be best to change your open to the complete path to the file that the user wants open.
    also, since you seem to be using an editor for your html, why not pull the html out of the perl

    Look into HTML::Template. It will make site updates much nicer and break less perl. html::template tutorial.

    here are the changes I would make:
    cgi file:

    #!/usr/bin/perl -wT use strict; my $video_info; # Loads the CGI Module use CGI; # creates a new CGI object my $page = new CGI; # This will print a standard HTML header print $page->header; # Grab a named CGI parameter my $value = $page->param("video"); #Open up the file that contains the review of the video open(SEE, "/var/www/docs/$value") or $video_info="$!"; while(<SEE>){ #put data from review into variable $video_info .= "$_"; } #close file close(SEE); #Now print out lots of HyperText Mark-up Language using # HTML::Template my $template = HTML::Template->new(filename => 'my.tmpl'); $template->param(info => $video_info); print $template->output; exit;

    and the template:
    <HTML> <HEAD> <META NAME="GENERATOR" CONTENT="Adobe PageMill 3.0 Win"> <TITLE>Animetion Station &gt; Video Review &gt; Oh MY Goddess! Volum +e 1</title> <LINK REL="stylesheet" HREF="../Style.css" TYPE="text/css"> </head> <BODY TEXT="#ffffff"> <P STYLE="background-color: #3257b8; width: 350px;"><I><FONT SIZE="+3" FACE="Garamond">Animetion Station</font></i></p> <div id="Bottom"> <P><I><FONT SIZE="+2" FACE="Garamond">Video Review</font></i></p> </div> <P><CENTER>&nbsp;</center></p> <P><TABLE WIDTH="738" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="24"> <TR> <TD WIDTH="67" VALIGN="TOP"> <div class="Standard"> <P><CENTER><A HREF="../index.htm">[Home]</a> <HR> <A HREF="../Gallery.shtml">[Gallery]</a> <HR> <A HREF="../Manga.shtml">[Manga]</a> <HR> <A HREF="../Video_Review.shtml">[Video Reviews]</a> <HR> <A HREF="../Links.shtml">[Links]</a> <HR> <A HREF="../Web_Comic.shtml">[Web Comic]</a></center></td> <TD VALIGN="TOP" WIDTH="270" HEIGHT="131"> </div> </td> <TD WIDTH="382" VALIGN="TOP"> <!-- this is the bit that HTML::Template wants so it knows where to pu +t the value of $video_info --> <TMPL_VAR NAME="info"> <!--VIDEO REVIEW LINKS--> <P STYLE="background-color: darkBlue;"> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fBattle_Skip +per_Vol_1.txt">Battle Skipper Volume One by Ertain</a><BR> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fOMG_Vol_1.t +xt">Oh My Goddess! Volume One by Ertain</a><BR> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fOMG_Vol_2.t +xt">Oh My Goddess! Volume Two by Ertain</a><BR> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fOMG_Vol_3.t +xt">Oh My Goddess! Volune Three by Ertain</a><BR> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fOMG_Vol_4.t +xt">Oh My Goddess! Volume Four by Ertain</a><BR> <A HREF="cgi-bin/Video_Gen.cgi?video=Video_Txt_Files%2fOMG_Vol_5.t +xt">Oh My Goddess! Volume Five by Ertain</a></p> </td> </tr> </table> </body> </html>

    -p

      I agree with thatguy, and if you are unsure of the exact path to your file (maybe because you are not the admin or whatever), and if it is in the same place as your script, you can always use the CWD module to grab the name of the current working directory...

      # Load the current working directory module use Cwd; # set $dir to the current directory my $dir = cwd; # print out the pathname print "My file is: $dir/$value\n";
        Sometimes the cwd isn't really what you want, though. If you want to know the directory in which the script resides (rather than the directory one was in when it was executed), a better solution is FindBin.

        -Blake