Perl's Zero-But-True ( 0e0 ) is a most handy tool (See String::ZeroButTrue). Return::DataButBool is a Perl module that expands on that idea by having a return value that has different boolean, numeric, and string values.
For example you could return a count of files processed (say 42 which is "true") but still say it failed in boolean context.
or you could return any false value ( not just '0' ) but still return true. The flexibility allows for all sorts of use.
SYNOPSIS
use Return::DataButBool;
sub whatever {
...
return $ok ? data_but_true( $count ) : data_but_false( $count, $error );
}
later in the code using this function:
my $total = 0;
for my $thing ( @stuff ) {
my $rc = whatever( $thing );
$total += $rc; # numeric value
if( !$rc ) { # boolean value
carp "Error happened: $rc"; # string value
}
}
Product's homepage
Requirements:
· Perl