10.10. Returning FailureProblemYou want to return a value indicating that your function failed. Solution
Use a bare return; Discussion
A sub empty_retval { return ( wantarray ? () : undef ); }
You can't use just if (@a = yourfunc()) { ... }
Then the "error" condition will be perceived as true, because unless ($a = sfunc()) { die "sfunc failed" } unless (@a = afunc()) { die "afunc failed" } unless (%a = hfunc()) { die "hfunc failed" }
Some of Perl's built-in functions have a peculiar return value. Both ioctl(....) or die "can't ioctl: $!";
That way, code doesn't have to check for a defined zero as distinct from the undefined value, as it would for the See Also
The
Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|