Skip to Content
Programming Perl, 3rd Edition
book

Programming Perl, 3rd Edition

by Larry Wall, Tom Christiansen, Jon Orwant
July 2000
Intermediate to advanced
1104 pages
35h 1m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 3rd Edition

Fatal

The Fatal module makes functions fail more spectacularly. It replaces functions that normally return false upon failure with wrappers that raise an exception if the real function returns false. That way you can safely use these functions without testing their return values explicitly on each call.

Both user-defined functions and built-in functions may be wrapped, except for those built-ins that cannot be expressed via prototypes. Attempting to override a nonoverridable built-in raises an exception. These include system, print, printf, exec, split, grep, and map—or more generally, any FUNC for which prototype "CORE::FUNC" returns false, including the prototype function itself.

If the symbol :void appears in the import list, functions named later in the list are limited to raising an exception when the function is called in void context—that is, when the return value is ignored. (Be careful about the last statement in a subroutine.) For example:

use Fatal qw(:void open close);

# open properly checked, so no exception is raised on failure.
if (open(FH, "< /nonesuch") { warn "no /nonesuch: $!"; }

# close not properly checked, so failure raises an exception.
close FH;
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Perl, 4th Edition

Programming Perl, 4th Edition

Tom Christiansen, brian d foy, Larry Wall, Jon Orwant
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes

Publisher Resources

ISBN: 0596000278Supplemental ContentErrata