Hi Rob I take care of everything that needs (execution errors) to be done within my sub. Perhaps this may help explain what I have:
A the beginning of my program I test to see what needs to be done, and if a conditional evaluates to true, then a sub is called to work and that is it. The program should not continue once a sub ends executing. If ($foo){ my_sub_foo(); # Is the program going to continue from here once sub foo has ended and I have not called exit here or in the sub? } elsif ($bar){ my_sub_bar(); } else { my_other_sub(); } sub foo { do everything that needs to be done. # I expect the program to end here once the sub has completed executing. } sub bar { do everything that needs to be done. # I expect the program to end here once the sub has completed executing. } Sub my_other_sub { ............... ............... # I expect the program to end here once the sub has completed executing. } As seen above, if a condition is met, then a sub is called to deal with it and the program should exit. My question is: what happens if I don't call exit in the last line of the sub or after calling the sub? Is the program going to continue running once the sub has ended? If my program will continue to evaluate the rest of the program, then is it efficient to call exit one time at the end of the program or call exit as the last line of each subroutine to ensure the program ends there? Mimi => You program will happily continue doing what you want it doens't care => that => you don't deal with the return value. => => So if you have code like this: => => do some stuff; => do some more; => call_a_sub(); => do some other stuff; => => => Your program will execute the first two lines, then do what ever the => sub => call_a_sub() wants it to do and return to do some other stuff without => you => having to worry about a return value. Keep in mind though that $_ has => likely => be altered by you sub. ;-) => => There always "good" reasons not to bother with return values but in => most => cases I would still say it is a sign of sloppy programming. => For the simple reason that you expect a sub to do something what ever => it is. => If this something fails you should, even if your code doesn't care => about the => result, inform the end user of this fact... you would not be the first => programmer that writes a program that seems to totally at random do => this one => thing or fail to do this without any apparent reason... a simple: => Failed to => execute something message written to STDERR if nothing else is just => one of => those things that makes the end users life a million times easier. => => Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/