I am in the midst of building my own message board one piece at a time. in this problem there is a
message board with one
link to a subject.
The script opens the text file to be searched, stores it in an array, and searches the array for the section to be displayed on the new page.
At the momment this code is not finding the search string, and thus displays nothing, except when you put an identical print statement between the
if and
while statements.
Here we go:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
#http://xxrainxx.tripod.com/cgi-bin/mboard.html test page
#http://xxrainxx.tripod.com/cgi-bin/postall.txt text file
open (INF,"postall.txt") or dienice("Couldn't open postall.txt for re
+ading: $!");
$subject = $ENV{'QUERY_STRING'};
$subject =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$subject =~ tr/_/ /;
@b = <INF>;
close (INF);
print <<"EndHTML";
<html><head><title>$subject</title></head>
<body bgcolor="#000000" text="#DDFFDD" face="Verdana,Helvetica,Arial">
+\n
$ENV{'QUERY_STRING'}\n<br>
$subject\n<br>
<br>
<blockquote>
Here's the message:\n<br>\n<br>\n
EndHTML
print "$subject this is what I'm looking for<br>\n";
for ($x=1;$x < scalar @b;$x++) {
if($b[$x]=="***Begin $subject"){
while ($b[$x]!="***Begin Here***\n"){
print "$b[$x]<br>\n";
$x = $x + 1;
}
}
}
#foreach $line (@b){
# chomp($line);
# print "$line<br>\n";
#}
# I removed a section of html when posting because last time closing t
+he textarea broke the preview text field.
sub dienice {
my($msg) = @_;
print "<h2>Error</h2>\n";
print "$msg;\n";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.