File and variable problem?

H

hakim

Hi,

My script looks like that:

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my @content;
6
7 open(FILE, "< content.txt");
8 @content = <FILE>;
9 close(FILE);
10
11 my $name = "Achim";
12
13 print @content;
14

content.txt:

Hello $name,

How are you?


If I start my script, I get only the contents of content.txt, but I
want that perl changes $name to Achim. I need something like that for
CGI programming.
What is the nicest way to do that or is it better to create functions
with the content and put it in a module? What's the nicest way for CGI
Programming???

Thanks...
 
P

phaylon

hakim said:
If I start my script, I get only the contents of content.txt, but I want
that perl changes $name to Achim. I need something like that for CGI
programming.

Just google for Template Engines, the're lots of them and I think that is
what you're looking for.

hth,p
 
M

Mark Clements

hakim said:
Hi,

My script looks like that:

Next time it would be better to drop the line numbers.
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my @content;
6
7 open(FILE, "< content.txt");
You need to check the return value of your system calls.
8 @content = <FILE>;
9 close(FILE);
10
11 my $name = "Achim";
12
13 print @content;
14

content.txt:

Hello $name,

How are you?


If I start my script, I get only the contents of content.txt, but I
want that perl changes $name to Achim. I need something like that for
CGI programming.
What is the nicest way to do that or is it better to create functions
with the content and put it in a module? What's the nicest way for CGI
Programming???

You need a templating solution: check something like

HTML::Template

on CPAN.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top