############## Initialize variables ################# $watcheddir="/samba/accpac/email"; chdir "$watcheddir"; use Mail::Sendmail; unshift @{$Mail::Sendmail::mailcfg{'smtp'}},'mail.aidusa.com'; ##################################################### ####### Translate salesperson number to name ######## %personname=('1001', 'Jerry Clavin', '1009', 'Mike Lay', '1020', 'Vernon Simpson', '1030', 'Mike Manuel', '1040', 'Ted Zerbey', '1050', 'Mark Akin', '1060', 'Mike Hendricks', '1500', 'Bill Taylor', '2003', 'House Account (OKC)', '2004', 'Vince Rada', '2007', 'Jerry Hopper', '2009', 'Bryan Montgomery', '3000', 'Mike Lay', '3100', 'Jerry Clavin', '5300', 'Mike Lay'); ##################################################### ##### Associate salesperson number with address ##### %personaddress=('1001', 'jclavin@aidusa.com', '1009', 'mlay@aidusa.com', '1020', 'vsimpson@aidusa.com', '1030', 'mmanuel@aidusa.com', '1040', 'tzerbey@aidusa.com', '1050', 'makin@aidusa.com', '1060', 'mhendricks@aidusa.com', '1500', 'btaylor@aidusa.com', '2003', 'jhopper@aidusa.com', '2004', 'vrada@aidusa.com', '2007', 'jhopper@aidusa.com', '2009', 'bmontgomery@aidusa.com', '3000', 'mlay@aidusa.com', '3100', 'jclavin@aidusa.com', '5300', 'mlay@aidusa.com'); ##################################################### ################## Monitor loop ##################### loop: opendir (DIR, $watcheddir); @files=grep {!/^\./} readdir (DIR);@files removing files that closedir DIR; foreach $currentfile (@files) { &filecontents; } sleep 10; goto loop; ##################################################### ########## Get Data from Printed File ############### ########## Send Message to Address ############### ########## Delete File After Success ############### sub filecontents { print "Current File: $currentfile\n"; $date=localtime(time); open FILE, $currentfile; $.=0; do { $firstline=; ($name, $value)=split(/=/, $firstline); $value =~ s/^\s+//; $value =~ s/\s+$//g; $value =~ s/\n//g; print "$name\=$value\n"; $data{$name}=$value; } while $.<5; if ($data{'SONUMBER'} eq "" || $data{'SALESPERSON'} eq "") { $data{'SONUMBER'}="No S.O. attached"; $data{'SALESPERSON'}="No salesperson assigned"; &sendemailspecial; } else{ &sendmailnormal; } unlink $currentfile; }