CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
On the fly web pages

 



John Bakos
Deleted

Jul 4, 2000, 6:34 AM

Post #1 of 2 (289 views)
On the fly web pages Can't Post

Not sure if this is a perl-based need. I have a standard web page template that I would like to change one (1) word for each user. Solution requires that I send a link to a user that would generate a unique web page, with only 1 word changed, when clicked. As a novice, headers and query strings have confused me. Would like to eliminate multiple page creation and ftp. It seems to be a simple requirement. Will accept toll-free calls at 800.370.5627 if it's a simple solution. Will also pay.

------------------


Kanji
User / Moderator

Jul 4, 2000, 12:17 PM

Post #2 of 2 (289 views)
Re: On the fly web pages [In reply to] Can't Post

There are a number of ways you can do this, but you don't give enough info about the word for me to give non-perl solutions, so here's a script that'll do ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

#!/usr/bin/perl -wT

my $file = '/path/to/template.html';
my $words = '/path/to/words.txt';

my($user) = $ENV{'PATH_INFO'} =~ m|^/(.*)|
if $ENV{'PATH_INFO'};

print "Content-Type: text/html\n\n";

my $word = lookup_word( $user ) if $user;

unless ( $word ) {
print "No user given or user invalid.";
exit;
}

if ( open FILE, $file ) {
while ( <FILE> ) {
s/%%CUSTOM_WORD%%/$word/g;
print;
}
} else {
print "Couldn't open $file because $!";
exit;
}

sub lookup_word {
my $user = shift;
if ( open WORDS, $words ) {
while ( <WORDS> ) {
next unless /^$user\s+(.+)/;
chomp( my $word = $1 );
return $word;
}
} else {
print "Couldn't open $words because $!";
exit;
}
return;
}</pre><HR></BLOCKQUOTE>

File names are purely arbritrary, but template.html would contain something like...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

<h2>Hello %%CUSTOM_WORD%%!</h2>
Yadda yadda yadda rhubarb.
</pre><HR></BLOCKQUOTE>
...where %%CUSTOM_WORD%% is where you want the word to appear.

words.txt, however, would look something like...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

USER WORD
---------- ----------
kanji World
jbakos John</pre><HR></BLOCKQUOTE>

If the script was called words.cgi, and you called it as http://somewhere.com/words.cgi/kanji the output should then be...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

<h2>Hello World!</h2>
Yadda yadda yadda rhubarb.</pre><HR></BLOCKQUOTE>

For serious templating the above is easily extended, but you'd probably be better off looking at CGI::FastTemplate or some such.

Anyway, hope that helps.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives