Gossamer Forum
Home : General : Perl Programming :

Fake dynamic script!

Quote Reply
Fake dynamic script!
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!

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.");
}
}
Quote Reply
Re: Fake dynamic script! In reply to
Im not sure what you want people to tell you.

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Fake dynamic script! In reply to
Oeps....offcourse; I didn't tell what I was wondering about.

I was:

- not sure what (-e "/users/www/data/$in{$db_key}.html") does.
- not sure when (OPEN) triggers an error.
- not sure what would be the serverload for opening the files (filesize ~ 30.000 bytes)
- not sure if this Is THE way to handle my problem :-)


OR actually THE QUESTION:

I made up this sullution because I thought building these pages dynamic would cost to much server capacity. This because for every page I need to open 5 txt files, do a couple lookup's like ($cattext{$data[2]}; I don't know how you call this?!) check referer and so..... But I don't know IF this is better/quicker. How can I measure this?

Quote Reply
Re: Fake dynamic script! In reply to
From reading your other posts as well as this, I think you are becoming too concerned with server load and processing times. I understand that it is an important factor in some cases but I think you are becoming overly concerned.

In Reply To:
- not sure what (-e "/users/www/data/$in{$db_key}.html") does.

You don't know what it does?......You wrote it didn't you?

The -e checks if the file exists, if not, nothing will happen.

In Reply To:
- not sure when (OPEN) triggers an error.
Open triggers an error when the file can't be opened.
As well as -e you can also use -w to check if the file is writable.

In Reply To:
- not sure what would be the serverload for opening the files (filesize ~ 30.000 bytes)
Not much unless you had many visitors doing it all at once.



Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Fake dynamic script! In reply to
Thanks Paul,

In Reply To:
From reading your other posts as well as this, I think you are becoming too concerned with server load and processing times. I understand
that it is an important factor in some cases but I think you are becoming overly concerned.
Indeed I am/was!

This because (If I can say myself) become real handy with perl; only about servers and apache I don't know sh#t. I have a shared server at UUNet; so the quality is good and therefore I think I'm going to use your advice.

...about the script: I always thought file opening was slow; but i never realized myself that I use a lot of file openings in my dynamic script. So I'm just going to do one! The opening op the complete static page. Thanks again for you advise....... And about by name: If you thought I was princess christina it's ok! Wink




Quote Reply
Re: Fake dynamic script! In reply to
Smile

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/