PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: "Dan Page" <Dan dot Page at notes dot fairchildsemi dot com>
Subject: Re: Out of memory
Date: Jul 22 1999 8:37PM


Here's the gist of it. I can't seem to see anything that would hold on to, but
then again I'm new at Perl.

$dbh = Sybase::DBlib->dblogin($user,$passwd,$server);
$start = time();
print "Inserting..$start\n";
while ($inline= ) {

     #initialize fields
     $ip = '';
     $time = '';
     $method = '';
     $url = '';
     @fields = ();
     $sql='';
     @fields=split(/ /,$inline); #split input by spaces

     if (length($fields[0]) > 255) {     $fields[0]=substr($fields[0],0,254)}
#eliminate path chars after 255

     $c++; #counter


     if ($fields[6]=~/cgi/) {  #eliminate chars from ? on, if cgi-bin
          $x = index($fields[6],'?');
          $fields[6]=substr($fields[6],0,$x-1);
     }

     $ip = $fields[0];

     #Reformat time here***************

     $time=substr($fields[3],4,3) . ' ' . substr($fields[3],1,2) . ' ' .
substr($fields[3],8,4);
     $time = $time . ' ' . substr($fields[3],13,8);
     if (substr($fields[3],13,2) < 12) {
          $time=$time . 'AM';

     } else {

          $time=$time . 'PM';
          if (substr($time,12,2)!=12) {substr($time,12,2) =
substr($time,12,2)-12;}

     }
     if (substr($time,12,2)==0) {substr($time,12,2) = 12;}

     #end time reformat*****************

     $method=substr($fields[5],1,length($fields[5]));
     $url=$fields[6];
     @dat=();
     #Check for valid method GET,POST etc
     $sql='select seq from req_methods where method = ' . "'" . $method ."'";
     $dbh->dbcmd($sql);
     $dbh->dbsqlexec;
     $dbh->dbresults;
     @dat=$dbh->dbnextrow();

     if ($dat[0]=='') {
          $sql ='insert into req_methods (method) values (' . "'" . $method
."')";
          $dbh->dbcmd($sql);
          $dbh->dbsqlexec;
          $dbh->dbresults;
          if ($dbh->DBCOUNT == 0) {
               print "$c\t$sql\n";
               $z=;
          }
          $sql='select seq from req_methods where method = ' . "'" . $method
."'";
          $dbh->dbcmd($sql);
          $dbh->dbsqlexec;
          $dbh->dbresults;
          @dat=$dbh->dbnextrow()
     }
     $method_seq=$dat[0];

     #check for URL existence
     $sql = 'select seq from urls where url = ' . "'" . $url . "'";
     $dbh->dbcmd($sql);
     $dbh->dbsqlexec;
     $dbh->dbresults;
     @dat=$dbh->dbnextrow();
     if ($dat[0]=='') {
          $sql ='insert into urls (url) values (' . "'" . $url ."')";
          $dbh->dbcmd($sql);
          $dbh->dbsqlexec;
          $dbh->dbresults;
          if ($dbh->DBCOUNT == 0) {
               print "$c\t$sql\n";
               $z=;
          }
          $sql='select seq from urls where url = ' . "'" . $url ."'";
          $dbh->dbcmd($sql);
          $dbh->dbsqlexec;
          $dbh->dbresults;
          @dat=$dbh->dbnextrow();

     }
     $url_seq = $dat[0];

     #Check for IP existence
     $sql = 'select seq from ip_addresses where ip_addr = ' . "'" . $ip . "'";
     $dbh->dbcmd($sql);
     $dbh->dbsqlexec;
     $dbh->dbresults;
     @dat=$dbh->dbnextrow();
     if ($dat[0]=='') {
          $sql ='insert into ip_addresses (ip_addr) values (' . "'" . $ip ."')";
          $dbh->dbcmd($sql);
          $dbh->dbsqlexec;
          $dbh->dbresults;
          if ($dbh->DBCOUNT == 0) {
               print "$c\t$sql\n";
               $z=;
          }
          $sql='select seq from ip_addresses where ip_addr = ' . "'" . $ip ."'";
          $dbh->dbcmd($sql);
          $dbh->dbsqlexec;
          $dbh->dbresults;
          @dat=$dbh->dbnextrow();
     }
     $ip_seq = $dat[0];

     #Insert into access_log table
     $sql= 'insert into access_logs (ip_seq,url_seq, req_seq, access_time)
values (';
     $sql = $sql .  $ip_seq . "," . $url_seq . "," . $method_seq . ",'" . $time
. "')";
     $dbh->dbcmd($sql);
     $dbh->dbsqlexec;
     $dbh->dbresults;
     if ($dbh->DBCOUNT == 0) {
          print "$c\t$sql\n";
          $z=;
     }



     print "counter: $c\r";

}

print "Counter: $c\n";
$end = (time()-$start);
print "$end\n";
close(LOG);
$dbh->dbclose;