bladx has asked for the wisdom of the Perl Monks concerning the following question:
Hi everyone.
I am back at it again, trying to get this news script project (that I have been working on for the past week) to work. I know that the easiest way to create a simple news script (and what I mean by a "news script" is a Perl-based CGI script that displays items from a database key and value hash.) I would like to be able to somewhere in my code be able to split elements of each line using a deliminator of | to seperate items such as the date of creation of article, the author, the title, the news, the avatar to go along with it, etc. But my problem is, I can't figure out (even after reading through the DB_File manpage,) how to do this. Is there a much better way to do this rather than to split a value of a key? (i.e. I am thinking of doing it like this: I have a key, then a value of something like: title|date|author|news and I would like to be able to split each individual key up so that I can use these variables or refrences in the HTML template later. That way I can have like a box of information using each variable from each value.
This is what I was planning on doing to create this news script, but is there a way I am missing, on how to do this sort of thing, using Perl and DB_File and HTML::Template? I hope that this time I have explained more about what I am doing than my past latest posts. For further clarification, the current .pl file I am doing this in is here:
Is there a way I can split each value in this script somewhere? If there is another way that is better than this way, please let me know! I don't want to be using something that is either old, or something that does not work at all. Thanks for any help.
Andy Summers
I am back at it again, trying to get this news script project (that I have been working on for the past week) to work. I know that the easiest way to create a simple news script (and what I mean by a "news script" is a Perl-based CGI script that displays items from a database key and value hash.) I would like to be able to somewhere in my code be able to split elements of each line using a deliminator of | to seperate items such as the date of creation of article, the author, the title, the news, the avatar to go along with it, etc. But my problem is, I can't figure out (even after reading through the DB_File manpage,) how to do this. Is there a much better way to do this rather than to split a value of a key? (i.e. I am thinking of doing it like this: I have a key, then a value of something like: title|date|author|news and I would like to be able to split each individual key up so that I can use these variables or refrences in the HTML template later. That way I can have like a box of information using each variable from each value.
This is what I was planning on doing to create this news script, but is there a way I am missing, on how to do this sort of thing, using Perl and DB_File and HTML::Template? I hope that this time I have explained more about what I am doing than my past latest posts. For further clarification, the current .pl file I am doing this in is here:
#!/usr/bin/perl -w use strict; use HTML::Template; use CGI::Carp qw(fatalsToBrowser); use DB_File; my @fields = ("title","date","author","news"); my $template = HTML::Template->new(filename => 'news.tmpl'); my $filename="database.db"; tie(my %hash, "DB_File", $filename) or die "Can't open $filename: $!"; my @loop_data = map { { KEY => $_, VALUE => $hash{$_} } } keys %hash; untie %hash; $template->param(SHOW_ALL_LOOP => \@loop_data); print $template->output;
Is there a way I can split each value in this script somewhere? If there is another way that is better than this way, please let me know! I don't want to be using something that is either old, or something that does not work at all. Thanks for any help.
Andy Summers
Edit ar0n -- title fix
|
---|
Replies are listed 'Best First'. | |
---|---|
(Ovid) Re: How can I create a "good" news script
by Ovid (Cardinal) on Jan 01, 2002 at 01:26 UTC | |
by TGI (Parson) on Jan 01, 2002 at 01:55 UTC |
Back to
Seekers of Perl Wisdom