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

I wanted to know if I need to save the flat file as a txt or html document. Would I then put that into a cgi-bin or not. Also, I have tried saving this as a CGI program but does not seem to work. I have also tried saving it as a PL document. Any help would be great.

#!/usr/local/bin/perl my $in; if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } else { $in = <STDIN>; } $in =~ s/\+/ /g; $in =~ s/%(..)/pack("c",hex($1))/ge; my %movie = split (/=/, $in); open (DATA, "/home/export/users/cis14/cheu0576631/public_html/cgi-bin/ +MovieList.txt"); my @data = <DATA>; close (DATA); print <<END; Content-Type: text/html\n\n <html> <body bgcolor="#000000" text="#ffffff"> <center><h2>Results</h2></center><p> <center><hr size=1 width=50%></center> END for ($i = 0; $i <= $#data; $i++) { if ($data[$i] =~ /-- $movie{'title'} --/i) { print <<END; <center><b><font size="+1">$data[$i + 1]</font></b></center><br> $data[$i + 2]<br> END last; } elsif ($i == $#data) { print "<b><i>Sorry! I haven't reviewed that one yet!</i></b>"; } } print <<END; <center><hr size=1 width=50%></center> </body> </html> END

Replies are listed 'Best First'.
Re: Flat-File
by Zaxo (Archbishop) on Nov 22, 2003 at 06:04 UTC

    You would do much better to use CGI; and take advantage of the param() method for figuring out the request. On the lost file, you should decide the absolute location of the file and make sure that's what you're looking at.

    After Compline,
    Zaxo

Re: Flat-File
by l3nz (Friar) on Nov 22, 2003 at 07:22 UTC
    I'd use the CGI modules too, because they are way better suited to what you are about to do.

    In any case, I would not try writing to the CGI-BIN directory (this might be a security hole) but I'd ask my sysadmin for a directory I can read and write to.

    In your code, I think it's useless to read all the lines of the movie database up front; I'd read wwhile I find the movie I'm interested in and skip the rest.

Re: Flat-File
by CountZero (Bishop) on Nov 22, 2003 at 13:45 UTC
    What do you mean with "does not seem to work"? "It doesn't run at all" or "It runs but it doesn't do what I want it to do"

    There is a world of difference between the two and before we can even think of offering any help, some more info would be helpful.

    Remark: this is another question related to searching a movie database (see Help with Perl movie database engine assignment). Homework?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law