in reply to Re^2: Perl Module Object - Return fail/success with a fault string
in thread Perl Module Object - Return fail/success with a fault string
The problem is that ! does not provide a numeric context.
use Scalar::Util qw[ dualvar ];; sub alwaysFails { return dualvar 0, 'Some text to explain the error'; +};; $rv = alwaysFails();; print "Sub failed with error: $rv" if !$rv;;
If you want 0 to stand for failed, you'd need to use a test that does provide a numeric context. Eg.
print "Sub failed with error: $rv" if ! 0+$rv;; Sub failed with error: Some text to explain the error print "Sub failed with error: $rv" if ~$rv;; Sub failed with error: Some text to explain the error print "Sub failed with error: $rv" if $rv == 0;; Sub failed with error: Some text to explain the error
|
|---|