For some static pages I have (all numbers) I would like to create an dynamic foreground!
Because I'm not sure how "open file"-command can be used best (and how to display errors at best) I would like to ask you your opinion bout this snippet. Here it comes!
# --------------------------------------------------------
local (%in) = &parse_form;
# We are processing the form.
if ($in{$db_key} =~ /^\d $/) {
$valid = 0;
if (-e "/users/www/data/$in{$db_key}.html") {
$valid = 1;
open (FILE, "</users/www/data/$in{$db_key}.html") or &display ("Unable to open file. Reason: $!");
$display = join ("", <FILE> );
close FILE;
}
if ($valid) {
$display =~ s/javascript:history.back()/$ENV{'HTTP_REFERER'}/g;
&html_print_headers;
print "$display";
} else {
&display ("Wrong ID: $in{$db_key}.");
}
}
# Otherwise we are displaying an error.
else {
&display ("Unable to display record.");
}
}
Because I'm not sure how "open file"-command can be used best (and how to display errors at best) I would like to ask you your opinion bout this snippet. Here it comes!
Code:
sub main { # --------------------------------------------------------
local (%in) = &parse_form;
# We are processing the form.
if ($in{$db_key} =~ /^\d $/) {
$valid = 0;
if (-e "/users/www/data/$in{$db_key}.html") {
$valid = 1;
open (FILE, "</users/www/data/$in{$db_key}.html") or &display ("Unable to open file. Reason: $!");
$display = join ("", <FILE> );
close FILE;
}
if ($valid) {
$display =~ s/javascript:history.back()/$ENV{'HTTP_REFERER'}/g;
&html_print_headers;
print "$display";
} else {
&display ("Wrong ID: $in{$db_key}.");
}
}
# Otherwise we are displaying an error.
else {
&display ("Unable to display record.");
}
}