CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Comparing logfile data against Database


New User

Oct 17, 2011, 10:02 AM

Post #1 of 2 (1252 views)
Comparing logfile data against Database Can't Post


Below script reads a log file which contains a list of Id's and then login to DB to select the same Id's.

Now can anyone help me how to list the unmatched id's between log file and Database and send an email as:

Logfile count =10
DB count = 9
Umatched ID list:

use strict; 
use warnings;
use DBI;

my $dir = '/usr/home/Scripts/Test';

# get the text files from the specified dir
opendir DIR, $dir or die "could not open directory $dir: $!";
my @files = grep /\.txt$/, readdir DIR;
closedir DIR;

my $dbh = DBI->connect("dbi:Oracle:****", "****", "*****" )
|| die( $DBI::errstr . "\n" );
$db->{AutoCommit} = 0;
$db->{RaiseError} = 1;
$db->{ora_check_sql} = 0;
$db->{RowCacheSize} = 16;

foreach my $fil (@files) {

# read the ids from the files

open IN, "$dir/$fil" or die "could not read $fil: $!";

#my @ids = map { chomp; "'$_'" } <IN>;

my @ids = map { "'$_'" } map { chomp; split /\s+/ } <IN>;

print "checking ", scalar(@ids), " ids from $fil\n";

my $sel=$db->prepare("select (number||'/'||id) as List_ID from Info where List_ID in (" . join(', ', @ids) . ')');
while(my $subref = $SEL->fetchrow_hashref()) {
my $list=$subref->{'LIST_ID'};
print "$list\n";



Oct 18, 2011, 8:57 AM

Post #2 of 2 (1163 views)
Re: [perl_user_84] Comparing logfile data against Database [In reply to] Can't Post

If I understand you right, you have two sets of IDs (one taken from the logfile, and one taken from the database), and you need those IDs which do NOT occur in both sets.

The straightforward way would be to model the two sets in Perl as hashes.

I personally would prefer the CPAN module Set::Scalar, because I like this user interface and the code gets more readable, but this is a matter of taste.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives