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:
#!/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


In reply to How can I create a "good" news script by bladx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.