Hello Everyone,

    I'm a newbie and need some help :-). I've been trying to get this Template, but, 
am running into lots of trouble. I apologize for how simple this is going to sound, 
but, this stuff is confusing! Ok, here is all I want to do, I have my little homepage 
with news I update daily. I wrote a script that will insert my updates into a CVS file 
like this:


Fill Me|4.19.2002|News filler cause what else do you write at 4AM? Only filler.... 
only filler.
Hurt|4.20.2002|I hit myself on the head today; still alive, will try again, tomorrow.

It goes HEADING|DATE|NEWS, so, I want to use Template Toolkit to pass this data to my 
template file. Here is what I have so far, but, I can't figure out how to separate the 
data by the |'s and update my news.

Here is what I have currently: test.cgi  (conveniently taken from the web tutorial)

#!/perl/bin/perl.exe

# use strict;
use Template;
use CGI;

my $q = new CGI;
print $q->header("text/html");

    my $file = 'templates/test.tmpl';
    my $vars = {
        'array'       => \&get_news
    };

    my $template = Template->new();
    $template->process($file, $vars) || die $template->error();
    

sub get_news {

    open(INF,"data/news.db");
    @news = <INF>;
    close(INF);

    return \@news;
}

and the template file: test.tmpl
[% FOREACH line = array %]
    [% line %]<p>
[% END %]

When I run test.cgi all it prints is:
Fill Me|4.19.2002|News filler cause what else do you write at 4AM? Only filler.... 
only filler.

Hurt|4.20.2002|I hit myself on the head today; still alive, will try again, tomorrow.


How can I separate all of this into variables so I can customize the output into a 
nicely formatted table? Also, Perl is the first language I�ve ever tried to learn 
after HTML, I would enjoy book suggestions: I've quickly read through CGI Programming 
101: Programming Perl for the World Wide Web. I bought CGI Programming with Perl but 
it�s too complicated for me, so, I was told to pick up Learning Perl next, any 
suggestions otherwise? I looked through January - latest list archive and someone 
mentioned their site is completely CVS driven, can you teach me a little :-).

Thanks,
Wassim Metallaoui



Reply via email to