CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
exit question

 



dwarf
Deleted

Aug 13, 2000, 8:45 PM

Post #1 of 7 (718 views)
exit question Can't Post

I have the following short script:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

#!/usr/bin/perl -w

foreach (("/usr/bin","/usr/sbin","/usr/local/bin")){
print "Found sendmail in $_\n" if -e $_."/sendmail";
}</pre><HR></BLOCKQUOTE>

It works like a charm, but has only one issue: it continues to loop even after sendmail is found and the mesage is printed. Is there any way to exit the script after sendmail was found, not using the regular if () {} syntax, but the one above??

Thanks!!


dwarf
Deleted

Aug 13, 2000, 11:21 PM

Post #2 of 7 (718 views)
Re: exit question [In reply to] Can't Post

Already did. The script ends after the first iteration which is not what I want. Any other way??


rGeoffrey
User / Moderator

Aug 14, 2000, 7:24 AM

Post #3 of 7 (718 views)
Re: exit question [In reply to] Can't Post

Try putting the 'exit' inside the 'if' so it will happen after the print, not just the first time through.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl -w
foreach ("/usr/bin","/usr/sbin","/usr/local/bin") {
if (-e $_."/sendmail") {
print "Found sendmail in $_\n";
exit;
}
}
</pre><HR></BLOCKQUOTE>


dwarf
Deleted

Aug 14, 2000, 7:55 AM

Post #4 of 7 (718 views)
Re: exit question [In reply to] Can't Post

I did it the first time around. The problem is that the code has to remain like it is. Is it even possible??


perlkid
stranger

Aug 14, 2000, 10:19 AM

Post #5 of 7 (718 views)
Re: exit question [In reply to] Can't Post

 
Try this,
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl -wforeach (("/usr/bin","/usr/sbin","/usr/local/bin")){print "Found sendmail in $_\n" if -e $_."/sendmail";
exit;
}

</pre><HR></BLOCKQUOTE>

perlkid


Kanji
User / Moderator

Aug 14, 2000, 1:34 PM

Post #6 of 7 (718 views)
Re: exit question [In reply to] Can't Post

Why does the code have to remain as is? I can't think of any logical reason why you would want to discount perfectly workable solutions, so doing such is incredibly arrogant.

Anyway, to answer your question, yes it's possible ...
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

print("..."), exit if -e "$_/sendmail";</pre><HR></BLOCKQUOTE>


dwarf
Deleted

Aug 14, 2000, 9:26 PM

Post #7 of 7 (718 views)
Re: exit question [In reply to] Can't Post

Thanks for the help. And I don't think it is arrogant to try to find out how far can you push something. I simply wanted to know if this is at all possible.

Thank you for your help again.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives