ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
10.10. Returning FailureProblemYou want to return a value indicating that your function failed. SolutionUse a bare return; DiscussionA 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 AlsoThe |