Octavian Rasnita wrote:
From: "Parag Kalra" <paragka...@gmail.com>

On shell, successful command returns exit status of 0.

As a best practice what status value shall a Perl function return.

Going by the fact that Perl function returns the value of last command
in it, I think function should return non-zero for a success.


Perl doesn't use functions, but subroutines or methods, so they don't
need to return something if you don't want them to return something.
If they return something they work like a function.

You are thinking of a language like BASIC where there is a distinction between functions, which return a value, and subroutines, which return nothing, and there are separate keywords to define each one.

Perl has operators/functions and subroutines (and keywords.)

print;

That is an example of an operator.

print();

And that is an example of a function.


So the subroutines may return arrays or scalar variables

Subroutines in Perl can only return lists of scalar values, never arrays.


which can also
be references to other kinds of variables if you need those variables as
a result of the subroutine.

If you just want to find if a subroutine returned true or false, you can
just return 1 or 0.

If you want to return a false value it is usually better to use return with no value:

return;

As that will return the correct false value in both scalar and list context.



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to