File and variable problem?

Discussion in 'Perl Misc' started by hakim, May 24, 2005.

  1. hakim

    hakim Guest

    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...
    hakim, May 24, 2005
    #1
    1. Advertising

  2. hakim

    phaylon Guest

    hakim wrote:

    > 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

    --
    http://www.dunkelheit.at/

    The eternal mistake of mankind is to set up an attainable ideal.
    -- Aleister Crowley
    phaylon, May 24, 2005
    #2
    1. Advertising

  3. hakim wrote:

    > 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
    Mark Clements, May 24, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    8
    Views:
    53,556
    saravanavsk
    Jan 25, 2010
  2. Kench
    Replies:
    2
    Views:
    5,407
    Victor Bazarov
    Jun 28, 2004
  3. mfglinux
    Replies:
    11
    Views:
    695
    Roberto Bonvallet
    Sep 12, 2007
  4. Matt
    Replies:
    2
    Views:
    237
    Hal Rosser
    Sep 26, 2004
  5. David Filmer
    Replies:
    19
    Views:
    237
    Kevin Collins
    May 21, 2004
Loading...

Share This Page