General discussion

Locked

Help with printing HTML in Perl

By vrindavan ·
I am new to perl (progging for about 1/2 a year now) and have stuck to simple code thus far, however, simple code has had me printing increasingly complicated and large HTML pages from the actual program file, and this has obviously resulted in horridly messy code.

So, I decided to step into unknown territories and have so far failed to solve this problem.

That is to say, what I'm trying to do is leave the references on the file then just print the file through the program, therefore slashing the program size and making the code much neater.

However, so far it has not recognised the variable references in the file. (I guess this is a simple problem for you guys, but hey)

here's a snapshot of what I'm doing:


HTML FILE: (created with dreamweaver)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
hello $nick
</body>
</html>

__________________
Prog: (created with Komodo)

#!/perl/bin -w
print "Content-type: text/html", "\n";
print "Pragma: no-cache", "\n\n";

$nick = "pumpingpump";

open (NICKTEST, "nicktest.htm");

$count = 0;
while ($nicktest = <NICKTEST&gt {
$nickstore[$count] = $nicktest;
$count += 1;
}

close (NICKTEST);

print (@nickstore);

__________________
the output is:

Content-type: text/html

Pragma: no-cache

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
hello $nick
</body>
</html>


and of course, if you have read the above, I want that $nick in the output to be "pumpingpump"
can you help me?

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

could you write an emulator for each instruction.......

by lawrephord In reply to Help with printing HTML i ...

Could you write an emulator for each instruction in perl using perl then using html then using xml then
using mx then using any other editor ?

Collapse -

Try this

by aaraujo In reply to Help with printing HTML i ...

In the body of your while loop, use this:

$nicktest =~ s/\$(\w+)/${$1}/g;
$nickstore[$count] = $nicktest;

instead of simply:

$nickstore[$count] = $nicktest;

Good luck !

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums