Re: HOW TO PARSE A VAST FILE!

From: Tore Aursand (tore_at_aursand.no)
Date: 03/19/04


Date: Fri, 19 Mar 2004 02:07:49 +0100

On Fri, 19 Mar 2004 01:05:53 +0800, news.hinet.net wrote:
> 163.22.3.7 2003/06/28 0011:00:42 PASSED
> http://proxy.ncnu.edu.tw/cgi-bin/squidGuard.cgi?clientaddr=163.22.28.128&clientname=ip128.puli28.ncnu.edu.tw&clientuser=&clientgroup=general-clients&targetgroup=moe&url=http://gatorcme.gator.com/gatorcme/autoupdate/precisiontime.ini
> 163.22.3.7 2003/06/28 0011:00:42 PASSED
> http://163.22.3.7/gatorcme/autoupdate/precisiontime.ini
> 163.22.3.7 2003/06/28 0011:00:43 PASSED
> http://proxy.ncnu.edu.tw/cgi-bin/squidGuard.cgi?clientaddr=163.22.9.25&clientname=ip025.puli09.ncnu.edu.tw&clientuser=&clientgroup=general-clients&targetgroup=moe&url=http://gatorcme.gator.com/gatorcme/autoupdate/installdatemanager.exe
> 163.22.3.7 2003/06/28 0011:00:43 PASSED
> http://163.22.3.3/gatorcme/autoupdate/installdatemanager.exe
> 218.172.162.134 2003/06/28 0011:00:44 PASSED
> http://liveupdate.symantecliveupdate.com/autoupdt.trg
> 218.172.162.134 2003/06/28 0011:00:44 PASSED
> http://202.239.172.95/autoupdt.trg
>
> [...]
> i want to find ip(163.22.3.7 218.172.162.134 ...) that are not exist in
> mysql.

There are two solutions here; The first is to read all the existing IP
addresses into a hash and check each one. The second one if to let MySQL
take care of the uniqueness of the IP address field (ie. setting that
field/column to unique in MySQL). The latter is probably the fastest (and
best way);

  my %ip_addresses;
  while ( <DATA> ) {
      if ( /^(.*?)\s+/ ) {
          $ip_addresses{$1}++;
      }
  }

  my $stInsert = $dbh->prepare( 'INSERT INTO ip_addresses (ip_address) VALUES (?)' );
  foreach ( keys %ip_addresses ) {
      $stInsert->execute( $_ );
  }
  $stInsert->finish();

-- 
Tore Aursand <tore@aursand.no>
"Writing is a lot like sex. At first you do it because you like it.
 Then you find yourself doing it for a few close friends and people you
 like. But if you're any good at all, you end up doing it for money."
 -- Unknown


Relevant Pages

  • Re: [Full-disclosure] Ioncube Encoded PHP Files
    ... > rather than change or server control. ... compares it against the hash of the password you want to see, ... permissions in the database, the irreversibility of hashes, or somesuch ... effort to find out it uses MySQL, and it is not likely very difficult to ...
    (Full-Disclosure)
  • answers
    ... >> courier imap. ... >> But we have not so much money this time. ... > server with possible upgrade path to a larger system. ... just apache2, mysql, postfix and courier imapd. ...
    (alt.os.linux)
  • Re: Moving MySQL database from one machine to another and remotely accessing dbs?
    ... Hash: SHA1 ... DuBois Mysql 4.1 book and Articfox said. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: IDS 11 - Press Releases
    ... Anyway, I make pretty good money as a consultant, doing better with Linux ... that Mac folks have to cough up $200 USD, a much more reasonable price. ... MySQL database is in operation in hundreds of data centers ... it's all about building market share. ...
    (comp.databases.informix)
  • Re: Moving MySQL database from one machine to another and remotely accessing dbs?
    ... Hash: SHA1 ... DuBois Mysql 4.1 book and Articfox said. ... there were read/writes while running mysqldump. ...
    (Debian-User)