On 2011-01-12 22:23, Parag Kalra wrote:

On shell, successful command returns exit status of 0.

As a best practice what status value shall a Perl function return.
A function can return other kinds of values too.

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.
It all depends. Read for example DBI(3), and see that some functions and
methods return handles, other return the number of touched rows (with
'0E0' as a special true zero), some will return a textual string, etc.

Often a worker function returns an undef (or an empty list) as a sign
that something didn't work out. This enables coding like:

my $foo = bar( @baz )
or die "huh? bar() failed!";

There are also subs that don't return anything. You can for example
write a sub that should change its parameters in place if the sub is
called in void context, for example C<trim( $text )>.


Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 12 | next ›
Discussion Overview
groupbeginners @
postedJan 12, '11 at 9:24p
activeJan 13, '11 at 10:39a



site design / logo © 2021 Grokbase