[thelist] Perl & Unix epoch

CDitty mail at redhotsweeps.com
Sun Apr 7 00:28:00 CST 2002


Found it.  For those that don't know, you can just use $epochTime =
time;.  Go figure.  :)

I have 2 other problems if anyone has the time to troubleshoot.  I am
trying to right a perl program that hits my database. In the program below,
when it is run, I get the error "TERM environment variable not set. ".  I
did a google search, but it looks like most pointed to using this on the
command line.  Any idea?

My other problem.is getting the output to display.  I had this running
several months ago, but I didn't retain enough to make it work again.  Anyone?

Thanks

Chris


#!/usr/bin/perl

use DBI;

$num_active = 10; # number of threads to show
$twentyfourhours = 24*60*60; # Last 24 hours in seconds
$epochTime = time; # Unix Epoch Time
$date1 = $epochTime - $twentyfourhours;

my $dbh = DBI->connect("dbi:mysql:database", "userid", "password") or
die("Failed to connect to Database");

my $sth = $dbh->prepare('select threadid, title from thread where
lastpost > $date1 and forumid <> 34 order by lastpost desc limit
$num_active') or die "Cant executer SQL statement: $DBI::errstr\n";

system('clear');

print "Content-type: text/html\n\n";

  while(my $sysname = <>) {

   my @data;
   chomp $sysname;

   $sth->execute($sysname) or die "Can't execute SQL statement:$DBI::errstr\n";
   print "ifDescr\tifInOctets\tifOutOctets\n";
   my @row;
    while (@row = $sth->fetchrow_array( )) {
      print " @row[0]\t$row[1]\n";
    }

   if($sth->rows == 0) {
     print "No Match for `$sysname`.\n\n";
   }

   print "\n";
}

$sth->finish;
$dbh->disconnect or warn "Error disconnecting: $DBI::errstr\n";




More information about the thelist mailing list