On Wed, Jul 21, 2010 at 5:00 AM, Babale Fongo <bfo...@googlemail.com> wrote:

> I call several subroutines within my program.  The program is design in a
> way that I don't expect my subroutines to return to the caller but to exit
> once they have executed.
>
> At the moment I don't have exit or return at the end of my subroutines.
>
>
>
> mysub(); # will the sub return here? If yes what happen if I don't capture
> it and act?
>
> ....
>
> .....
>
> ...
>
> reset of the code
>
>
>
> sub mysub{
>
>       do this
>
>      don that
>
>      ...
>
>     # I don't call exit or return
>
> }
>
>
>
>
>
> I understand a sub will normally implicitly return the last thing it
> evaluation, but what happens if I don't act on what has been returned to
> the
> caller? Will be programme stall because it doesn't know what to do next or
> will it exit?
>
>
>
>  Mimi
>
> Hi 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

Reply via email to