Thursday, September 30, 2010

Compare two mail addresses

#!/usr/bin/perl
use DBI;
%MYSQL = (
hostname => "localhost",
username => "root",
password => "",
database => "asterisk"
);

my $sender= 'abc@onvi.com';
$sender=$ARGV[0];
$sender=~ s/@/\@/;# replace @ with \2 in mail address

# connect to DB
my $dbh = DBI->connect("dbi:mysql:$MYSQL{database}:$MYSQL{hostname}","$MYSQL{username}","$MYSQL{password}");

my $qry = "SELECT * FROM test;";
#print $qry."\n";
my $result = $dbh->prepare($qry);
$result->execute();
my $tmp='';

# write to file
while (@row = $result->fetchrow()) {
$tmp=@row[1]; # assign mail addres to $tmp variable
$tmp=~ s/@/\@/; # replace @ with \2 in mail address

#print $sender." <---> ".$tmp."\n";

if($tmp eq $sender){
print $tmp."==".$sender."\n";
}


#print @row[0]."-->".$tmp."\n";
}#while