Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
Below script reads a log file (which contains a list of id's) and selects the same Data from the log file with the Oracle tables.
Can someone help how to extent the script in a way that :
when selecting /reading if it finds unmatched id's it has to send an email with the Body of the email as:
log: 17
Database: 16
list of not found id :
id1
id2
#!user/local/bin/perl 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"; print"@ids\n\n"; my $sel=$db->prepare("select (number||'/'||id) as List_ID from Info wh +ere List_ID in (" . join(', ', @ids) . ')'); $sel->execute(); while(my $subref = $SEL->fetchrow_hashref()) { my $list=$subref->{'LIST_ID'}; print "$list\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing Data to Email body from Perl
by zentara (Cardinal) on Oct 17, 2011 at 16:04 UTC | |
by Anonymous Monk on Oct 17, 2011 at 16:52 UTC | |
by Corion (Patriarch) on Oct 17, 2011 at 17:06 UTC | |
|
Re: Printing Data to Email body from Perl
by zentara (Cardinal) on Oct 17, 2011 at 17:49 UTC |