FAQ

Octavian Rasnita wrote:
From: "Parag Kalra" <paragkalra@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

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 7 of 12 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedJan 12, '11 at 9:24p
activeJan 13, '11 at 10:39a
posts12
users7
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase