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.
# --------------------------------------------------------
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.");
}
}
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.");
}
}