Ok, thanks to joe_camel, I have this much going so far:
#!/usr/bin/perl -w
use strict;
print "Content-type:text/html\n\n";
# Grab each line in reverse order
open (NEWS, "<data/news.txt") or die "Can't open news file: $!";
my @articles = reverse <NEWS>;
close(NEWS);
# Your column names, in the order they appear in the file
my @colNames = qw(time_stamp title date author news avatar);
# Store the contents of the file in a data structure
# (array of hashrefs)
my @table = ();
foreach my $article (@articles)
{
chomp $article;
my @vals = split (/\|/, $article);
# Assign each value to its column name, in a hash
my %row = ();
print<<HTML;
<table width=400 border=1 cellspacing=0 cellpadding=0>
HTML
foreach my $col (@colNames)
{
$row{$col} = shift @vals;
print<<HTML;
<tr>
<td>
$row{$col}
</td>
</tr>
HTML
}
print<<HTML;
</table>
<br>
HTML
# Add this row to the table, as a hashref
push @table, \%row;
}
however, I have no clue how to get it to take out a few of the fields ( the time_stamp, and the avatar fields.) I do not what these fields to show up when the news is posted, even though they are there for sorting later.
Can anyone show me how to do this? Thanks!
Andy
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.