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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stuck in a loop- 1

Status
Not open for further replies.

rebeccah2004

Programmer
Nov 20, 2003
17
US
Hello-
i am rather new to perl so the answer to my problem may be obvious. but i am writing a little perl script to back up a database, copy the dump to an offsite location, then email me the log when it is all done. i have it all working except when it emails me, it gets stuck in a loop and keeps emailing me the log until i kill it. any bit of help would be GREATLY appreciated. here is the code that is looping:

### batch script to email log when complete
my $filename = "tran.log";
my $found = 0;

open( FIN, &quot;<$filename&quot; );

while( <FIN> )
{
chomp;
if (substr($_,0,50) eq &quot;$fatal&quot;)
{
$found = 1;
system(&quot;perl fatal_error.pl tran.log&quot;);
}

else {
system(&quot;perl customer.pl tran.log&quot;);
}
}

close ( FIN );

...what i would like it to do is search the log for the word &quot;fatal&quot;, and if it see's it in there, then it runs a seperate perl script, but if &quot;fatal&quot; is not there it runs a different perl script.

any thoughts on what i am doing wrong?

thanks,
rebecca
 
Hi,

You need to wait until you've finished looking through the log file before you make a decision on your email; something like this perhaps:

### batch script to email log when complete
my $filename = &quot;tran.log&quot;;
my $found = 0;

open( FIN, &quot;<$filename&quot; );

while( <FIN> )
{
chomp;
if (substr($_,0,50) eq &quot;$fatal&quot;)
{
$found = 1;
}
}

close ( FIN );
if($found){
system(&quot;perl fatal_error.pl tran.log&quot;);
} else {
system(&quot;perl customer.pl tran.log&quot;);
}

You haven't, I notice, set the value of your variable $fatal in your example; I'm presuming it's set elsewhere.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
No problem, pass the favour on to someone else here :)

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top