For sake of example, suppost I have 3 text data files. What is a
simple way to create HTML/JavaScript on-the-fly building a file that
will use only the data file requested?
I am under the impression that I can replace 200 static HTML file with
a single (maybe two) PerlScript files. Is that right?
Sent via Deja.com http://www.deja.com/
Before you buy.
<myTITLE>My article</myTITLE>
<TEXT>Whatever is written</TEXT>
It is also stored in an archive with several other textfiles that
represents the text you want to produce.
-----------------------------------------------------------
In your links on your static page, you can have one file that you open
and you send, in the querystring, the filename that you want to open,
for example:
<A HREF="open.asp?file=somefile.txt">, or maybe even better <A
HREF="open.asp?file=somefile">, then in the file "open.asp", you have
the following code:
my $File = $Request->Querystring("file")->Item();
$File=~s/\0/
# If something was passed in the querystring, the call to
# "defined" will return 1, and the below is simply a way of
# writing if(defined($File)) { openfile ... } else {openfile(default
# ...)} etc
#
defined($File) ? openfile("$File.txt") : openfile("default.txt");
# shift returns the first element is the array in which Perl always
# passes subroutine parameters. If opening the file fails, the sub
# redirect is called. If it succeeds, we localize $/, which is a
# special variable documented inthe Perldocs, then read the contents
# of the textfile in.
#
sub openfile {
open(F, $Server->MapPath(shift)) or redirect();
local($/);
$Body=<F>;
close(F);
}
sub redirect {
$Response->Redirect("Http://www.petrovich.com");
}
--------
From the operation above, the scalar $Body will contain the contents of
your textfile, so to extract the contents between the two tags, you can
do this:
my ($DocTitle)=($Body=~/<myTITLE>(.*?)<\/myTITLE>/);
my ($DocText)=($Body=~/<TEXT>(.*?)<\/TEXT>/s);
Then you have the contents, and you can output it in your ASP document
such as
<FONT FACE="ARIAL" SIZE="+2"><%=$DocTitle%></FONT>
<BR>
<BR>
<%=$DocText%>
All the above should work, and you can pass the filename to the script
anyway you please, either by a HREF or another method. Since you are
going to open files that way, you may want to take a look at the
following article: http://www.phrack.com/search.phtml?view&article=p55-7
Follow their advise on regular expressions on the filename ($File)
before you open anything. Let me know if something doesn't work or is
unclear somewhere, and I'll elaborate.
--
Tobias