I apologize in advance for the obvious display of ignorance in this question. I have searched for a previously posted solution to this problem but have yet to find one that works.
I have a cgi script that opens a log file and assigns each ~ delimited value to a variable. It then prints each line of the log file in a particular format in html.
One of the variables in the logfile is date. I'm wondering if there is a way this script can open the file, sort by the $date variable, and print the log line item with the most current date first. If it has to rewrite the logfile, that is fine.
I have read several comments about creating a temp file and rewriting it, etc., but would really like to find a way to sort by date prior to printing the html.
Below is a line from the log file and a copy of the code that opens the log file and prints:
The Dow Dips to All-Time Low ~ http://www.yahoofinance.com ~ Yahoo Finance ~ 09/15/01 ~ The Dow Jones dipped to an all-time....
$from = "news.dat";
open(FILE, "$from") || die "Can't open $from!\n";
while (<FILE>) {
chop;
($title,$url,$site,$date,$description) = split(/~/,$_);
print "<table width=400><tr>";
print "<td><a href=\"$url\"><font color=blue>$title</font></a><br>
+<font color=black>$date,$site<br>$description</font></td>";
print "</tr></table><br>";
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.