Gossamer Forum
Home : General : Perl Programming :

Did I miss something...

Quote Reply
Did I miss something...
This one seems onsolvable.

The scripts (actually the sub process_form) should check if a file exist (based on it's input) and open the file.

If the script can't open it, it should only show the search form.

But what happens is no file exists, it prints out the searchform and "Content-type: text/plain Unable to display results." While the script should have returned and not even read the last parts.

Strange or not?

Offcourse I could removed the last part, but I'm curious what I'm doing wrong. Just to learn and understand return better. Because what would happen if return doesn't work and I don't have a second ok check.

Code:
sub main {
# --------------------------------------------------------
local (%in) = &parse_form;

# We are processing the form.
if (keys %in != 0) {
&process_form;
}
# Otherwise we are displaying the form (in site_html.pl).
else {
&site_html_search_form;
}
}

sub process_form {
# --------------------------------------------------------
my ($found, $htmlfile);

my $page = $in{'page'} || '1';
my $dir = $cathtml{$in{'cat'}} || 'all';
my $location = "$build_root_path/$dir/$page.html";

# Let's get the category html-page out of the correct dir.
if (-e "$location") {
$found = 1;
open (FILE, "<$location") or &display ("Unable to open file. Reason: $!");
$htmlfile = join ("", <FILE> );
close FILE;
}
$found or &site_html_search_form and return;


# Now let's display the record...
if ($found) {
&html_print_headers;
print $htmlfile;
} else { # just double checking
&display ("Unable to display results.");
}
}

Last edited by:

Perlboy Chris: Nov 21, 2001, 1:56 PM
Subject Author Views Date
Thread Did I miss something... cK 3590 Nov 21, 2001, 1:39 PM
Thread Re: [Perlboy Chris] Did I miss something...
Paul 3451 Nov 21, 2001, 2:16 PM
Post Re: [PaulW] Did I miss something...
cK 3442 Nov 21, 2001, 2:26 PM
Thread Re: [Perlboy Chris] Did I miss something...
Chaz 3460 Nov 21, 2001, 2:30 PM
Thread Re: [CP] Did I miss something...
cK 3451 Nov 21, 2001, 2:48 PM
Post Re: [Perlboy Chris] Did I miss something...
Paul 3441 Nov 21, 2001, 2:51 PM