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: Intermediate:
Reading Web Pages with Variables!

 



benchivers
Novice

Apr 15, 2002, 1:43 PM

Post #1 of 5 (448 views)
Reading Web Pages with Variables! Can't Post

I am making a cgi program, where the program reads the html code from a web page, and then prints the html code on screen, like so:



open(HTML,"<file.htm");

@data = <HTML>;

close(HTML);



print "@data";



I have placed variables within this web page like:

$title

$hyperlink

$text

and so on,

when I use the following source code, the actual variables print out on screen, instead of what they are equal to.

$title = "Ben";

$hyperlink = "www.hyperlink";

$text = "hello!";

open(HTML,"<file.htm");

@data = <HTML>;

close(HTML);



print "@data";

does anyone know how to print the variables on screen as what they are equal to, and not the actual variable word itselfs.

The file must be opened and read from. I think it can be solved using the substitute method or something like it, but I don't know how it works.

I hope this all makes sense!

I would appreciate any help!

Regards,

Ben Chivers
Wheres the damn coffee? zzzZZZZZ!!!


yapp
User

Apr 16, 2002, 7:54 AM

Post #2 of 5 (440 views)
Re: [benchivers] Reading Web Pages with Variables! [In reply to] Can't Post

So in other words, you would like to have some sort of template parser? Well, there are a lot of template parsers at the web.

Many programmers (including me) have written their own template parsers.

A good "common, usable" template parser is [url=http://search.cpan.org/search?mode=module&query=HTML%3A%3ATemplate]HTML::Template, and has lot's of features.

Yet Another Perl Programmer

_________________________________
~~> [url=http://www.codingdomain.com]www.codingdomain.com <~~
More then 3500 X-Forum [url=http://www.codingdomain.com/cgi-perl/downloads/x-forum]Downloads! Cool


Pro_4
User

Apr 17, 2002, 1:04 PM

Post #3 of 5 (433 views)
Re: [yapp] Reading Web Pages with Variables! [In reply to] Can't Post

I'm sure you already know this but print "@data"; doesnt work..... :) just a heads up if that happened to be yo problem.


yapp
User

Apr 18, 2002, 12:25 AM

Post #4 of 5 (428 views)
Re: [Pro_4] Reading Web Pages with Variables! [In reply to] Can't Post

print "@data"; concatenates the array into a string.
print @data; just prints the fields of the array. This is the same as print $data[0], $data[1], $data[2] .... $data[n];

Yet Another Perl Programmer

_________________________________
~~> [url=http://www.codingdomain.com]www.codingdomain.com <~~
More then 3500 X-Forum [url=http://www.codingdomain.com/cgi-perl/downloads/x-forum]Downloads! Cool


ka0osk
Novice

Apr 18, 2002, 5:53 AM

Post #5 of 5 (423 views)
Re: [benchivers] Reading Web Pages with Variables! [In reply to] Can't Post

if you surround your variables with an indicator like this: %%yourvar%% in the htm file, this should do the trick(pardon typos etc):

$page = yourpage.htm;
open (PAGE, "$page") || die;
while (<PAGE>)
{
s/%%first_variable%%/$first_variable/g;
s/%%second_variable%%/$second_variable/g;
print $_;
}
close (PAGE);


Good luck!
John Step;Shocked

 
 


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

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