I need some assistance again. I asked in the CB but it seemed like everyone had a different method of doing this and it seemed a lot more complicated than what could be described in the CB. I am NOT asking for source code, all I want is suggestions or places to look.

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; }


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

In reply to Retrieve last elements of a DB by sulfericacid

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.