sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:
I am writing my version of the CB, my first problem is right now the script doesn't push off older messages, it'll post 1000 comments. How can I print only the latest 10 elements of a database? Databases are put together in the order they come in, right? If so, I won't need a timestamp, right?
Problem is I can't delete the older messages because I want to have a past history log of the past 24 hours. What exactly is a timestamp? I know how to find the localtime but I'm thinking a timestamp is something totally different (I already searched the wizard).
Ok, in short I want to know how I would get the latest 10 things from a database to print to the screen without deleting them because I want to have a past history, too.
Any suggestions but no real code would be very helpful. Thank you so much!
What I have so far is the basic system, you post your name and message and it saves to the DB.
#!/usr/bin/perl -w open( STDERR, ">>/home/sulfericacid/public_html/error.log" ) or die "Cannot open error log, weird...an error opening an error log +: $!"; use strict; use warnings; use POSIX; use CGI qw/:standard/; require SDBM_File; my %chat; my $chat = "list.dbm"; my $file = "iplog.txt"; tie %chat, 'SDBM_File', $chat, O_CREAT | O_RDWR, 0644; if ( !tied %chat ) { print "database unsuccessful $!.\n"; } print header, start_html; print "<table>"; foreach ( keys(%chat) ) { print "<tr><td>"; my ( $one, $two ) = split /::/, $chat{$_}; print "<font color=blue>$one:</font> $two"; print "</td></tr>"; } print "</table>"; print start_form(), table( Tr( td("Name: "), td( textfield( -name => 'name', -size => 40 ) ) ), Tr( td("Message: "), td( textfield( -name => 'message', -size => 150 ) ) ), Tr( td(), td(submit) ), ), end_form(), hr(); if ( param() ) { my $name = param('name'); my $message = param('message'); my $cnt; open( LOG, "$file" ); $cnt = <LOG>; close(LOG); $cnt++; open( LOG, "> $file" ); print LOG $cnt; close(LOG); my $info = join ( '::', $name, $message ); $chat{$cnt} = $info; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Retrieve last elements of a DB
by Abigail-II (Bishop) on Jun 24, 2003 at 02:17 UTC | |
|
Re: Retrieve last elements of a DB
by VSarkiss (Monsignor) on Jun 24, 2003 at 02:32 UTC | |
|
Re: Retrieve last elements of a DB
by dws (Chancellor) on Jun 24, 2003 at 06:57 UTC |