Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Slow exection

Status
Not open for further replies.

thendal

Programmer
Aug 23, 2000
284
Hi!

when i try to execute the following mail program it takes long to execute (aprox 40-50 sec).Am i following the wrong way advice me

All i need is

i am having an array which contains 6 email ids,I have to send a mail to them

here is the code

$mailprog = '/usr/lib/sendmail';

for($l=0;$l<@mailid;$l++)
{
open(MAIL,&quot;|$mailprog -t&quot;);
$from='test@testmail.com';
$mailarray=$mailid[$l].'@ford.com';
print MAIL &quot;To: $mailarray \n&quot;;
print MAIL &quot;From:$from \n&quot;;
print MAIL &quot;Subject: Test Test \n\n&quot;;
print MAIL &quot;Test\n&quot;;
close (MAIL);
}


And what changes i have to make if i need to send mail in html format.

Thanks for any help

Regards,
thendal

 
i'm not sure about sending mail in html format, but

$| is a special variable in perl... it sets buffering.

use another variable name....

most strange characters have special meaning in perl, i'd avoid their use in the future as variable names, because you may be setting something that could be disastrous, without knowing it. anyway, change your variable name, and it will probably improve the speed of your program.
 
another thing...

you may want to use the foreach loop instead of for.

foreach $mailid (@mailid)
{

}

might make for quicker execution.

if your variable in your for loop is an l and not a | disregard my bantering above.

but you might also see some better performance if you set $| = 1;

this removes buffering, so that print prints when executed instead of accumulating in a buffer before being printed.
 
Thank you lucid dream for your quick reponse,
In the first case iam not using $|, iam using $l;

And Also i tried with $|=1 and foreach loop;

Iam accustomed to use FOR loop(I like FOR loop)
is that foreach loop is faster than for loop

Also I didn't see much difference in the speed.
 
Send the mail only once, but make each address a blind carbon copy. Also, you should send the process to the background and send all output to /dev/null. I'm still researching Perl's forking capabilities to do it that way.
Code:
open (MAIL, &quot;| /usr/sbin/sendmail -t >& /dev/null&quot;);
print MAIL qq~To: &quot;$title&quot; <$return_addr>\n~;
print MAIL qq~Bcc: ~;

my $address = pop(@LIST);
print MAIL qq~$address~;
foreach $address (@LIST) {print MAIL qq~, $address~;}

print MAIL qq~\nFrom: &quot;$return_name&quot; <$return_addr>\n~;
print MAIL qq~Reply-To: $return_addr\n~;
print MAIL qq~List-Unsubscribe: $return_addr\n~;
print MAIL qq~Subject: $subject\n~;
print MAIL qq~Content-Type: text/plain; charset=us-ascii\n\n~;
print MAIL qq~$body_text\n~;
print MAIL qq~.~;

close(MAIL);
I think my variables above are fairly self-explanatory. @LIST is your list to send to, etc.

To send HTML formatted emails, your Content-Type needs to be text/html.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Thanks Tom,It worked well,Really iam also think about how to make perl to process in the background.That will make the application so faster at the user end.

Iam struck in between a problem thats what iam not able to get you back immediately.Thanks for your help


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top