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 )>.
--
Ruud
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/