{
    "mode": "perldoc",
    "parameter": "autodie",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/autodie/json",
    "generated": "2026-06-13T21:26:01Z",
    "synopsis": "use autodie;            # Recommended: implies 'use autodie qw(:default)'\nuse autodie qw(:all);   # Recommended more: defaults and system/exec.\nuse autodie qw(open close);   # open/close succeed or die\nopen(my $fh, \"<\", $filename); # No need to check!\n{\nno autodie qw(open);          # open failures won't die\nopen(my $fh, \"<\", $filename); # Could fail silently!\nno autodie;                   # disable all autodies\n}\nprint \"Hello World\" or die $!;    # autodie DOESN'T check print!",
    "sections": {
        "NAME": {
            "content": "autodie - Replace functions with ones that succeed or die with lexical scope\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use autodie;            # Recommended: implies 'use autodie qw(:default)'\n\nuse autodie qw(:all);   # Recommended more: defaults and system/exec.\n\nuse autodie qw(open close);   # open/close succeed or die\n\nopen(my $fh, \"<\", $filename); # No need to check!\n\n{\nno autodie qw(open);          # open failures won't die\nopen(my $fh, \"<\", $filename); # Could fail silently!\nno autodie;                   # disable all autodies\n}\n\nprint \"Hello World\" or die $!;    # autodie DOESN'T check print!\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "bIlujDI' yIchegh()Qo'; yIHegh()!\n\nIt is better to die() than to return() in failure.\n\n-- Klingon programming proverb.\n\nThe \"autodie\" pragma provides a convenient way to replace functions that normally return false\non failure with equivalents that throw an exception on failure.\n\nThe \"autodie\" pragma has *lexical scope*, meaning that functions and subroutines altered with\n\"autodie\" will only change their behaviour until the end of the enclosing block, file, or\n\"eval\".\n\nIf \"system\" is specified as an argument to \"autodie\", then it uses IPC::System::Simple to do the\nheavy lifting. See the description of that module for more information.\n",
            "subsections": []
        },
        "EXCEPTIONS": {
            "content": "Exceptions produced by the \"autodie\" pragma are members of the autodie::exception class. The\npreferred way to work with these exceptions under Perl 5.10 is as follows:\n\neval {\nuse autodie;\n\nopen(my $fh, '<', $somefile);\n\nmy @records = <$fh>;\n\n# Do things with @records...\n\nclose($fh);\n};\n\nif ($@ and $@->isa('autodie::exception')) {\nif ($@->matches('open')) { print \"Error from open\\n\";   }\nif ($@->matches(':io' )) { print \"Non-open, IO error.\"; }\n} elsif ($@) {\n# A non-autodie exception.\n}\n\nSee autodie::exception for further information on interrogating exceptions.\n",
            "subsections": []
        },
        "CATEGORIES": {
            "content": "Autodie uses a simple set of categories to group together similar built-ins. Requesting a\ncategory type (starting with a colon) will enable autodie for all built-ins beneath that\ncategory. For example, requesting \":file\" will enable autodie for \"close\", \"fcntl\", \"open\" and\n\"sysopen\".\n\nThe categories are currently:\n\n:all\n:default\n:io\nread\nseek\nsysread\nsysseek\nsyswrite\n:dbm\ndbmclose\ndbmopen\n:file\nbinmode\nclose\nchmod\nchown\nfcntl\nflock\nioctl\nopen\nsysopen\ntruncate\n:filesys\nchdir\nclosedir\nopendir\nlink\nmkdir\nreadlink\nrename\nrmdir\nsymlink\nunlink\n:ipc\nkill\npipe\n:msg\nmsgctl\nmsgget\nmsgrcv\nmsgsnd\n:semaphore\nsemctl\nsemget\nsemop\n:shm\nshmctl\nshmget\nshmread\n:socket\naccept\nbind\nconnect\ngetsockopt\nlisten\nrecv\nsend\nsetsockopt\nshutdown\nsocketpair\n:threads\nfork\n:system\nsystem\nexec\n\nNote that while the above category system is presently a strict hierarchy, this should not be\nassumed.\n\nA plain \"use autodie\" implies \"use autodie qw(:default)\". Note that \"system\" and \"exec\" are not\nenabled by default. \"system\" requires the optional IPC::System::Simple module to be installed,\nand enabling \"system\" or \"exec\" will invalidate their exotic forms. See \"BUGS\" below for more\ndetails.\n\nThe syntax:\n\nuse autodie qw(:1.994);\n\nallows the \":default\" list from a particular version to be used. This provides the convenience\nof using the default methods, but the surety that no behavioral changes will occur if the\n\"autodie\" module is upgraded.\n\n\"autodie\" can be enabled for all of Perl's built-ins, including \"system\" and \"exec\" with:\n\nuse autodie qw(:all);\n",
            "subsections": []
        },
        "FUNCTION SPECIFIC NOTES": {
            "content": "print\nThe autodie pragma does not check calls to \"print\".\n\nflock\nIt is not considered an error for \"flock\" to return false if it fails due to an \"EWOULDBLOCK\"\n(or equivalent) condition. This means one can still use the common convention of testing the\nreturn value of \"flock\" when called with the \"LOCKNB\" option:\n\nuse autodie;\n\nif ( flock($fh, LOCKEX | LOCKNB) ) {\n# We have a lock\n}\n\nAutodying \"flock\" will generate an exception if \"flock\" returns false with any other error.\n\nsystem/exec\nThe \"system\" built-in is considered to have failed in the following circumstances:\n\n*   The command does not start.\n\n*   The command is killed by a signal.\n\n*   The command returns a non-zero exit value (but see below).\n\nOn success, the autodying form of \"system\" returns the *exit value* rather than the contents of\n$?.\n\nAdditional allowable exit values can be supplied as an optional first argument to autodying\n\"system\":\n\nsystem( [ 0, 1, 2 ], $cmd, @args);  # 0,1,2 are good exit values\n\n\"autodie\" uses the IPC::System::Simple module to change \"system\". See its documentation for\nfurther information.\n\nApplying \"autodie\" to \"system\" or \"exec\" causes the exotic forms \"system { $cmd } @args \" or\n\"exec { $cmd } @args\" to be considered a syntax error until the end of the lexical scope. If you\nreally need to use the exotic form, you can call \"CORE::system\" or \"CORE::exec\" instead, or use\n\"no autodie qw(system exec)\" before calling the exotic form.\n",
            "subsections": []
        },
        "GOTCHAS": {
            "content": "Functions called in list context are assumed to have failed if they return an empty list, or a\nlist consisting only of a single undef element.\n\nSome builtins (e.g. \"chdir\" or \"truncate\") has a call signature that cannot completely be\nrepresented with a Perl prototype. This means that some valid Perl code will be invalid under\nautodie. As an example:\n\nchdir(BAREWORD);\n\nWithout autodie (and assuming BAREWORD is an open filehandle/dirhandle) this is a valid call to\nchdir. But under autodie, \"chdir\" will behave like it had the prototype \";$\" and thus BAREWORD\nwill be a syntax error (under \"use strict\". Without strict, it will interpreted as a filename).\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": ":void cannot be used with lexical scope\nThe \":void\" option is supported in Fatal, but not \"autodie\". To workaround this, \"autodie\"\nmay be explicitly disabled until the end of the current block with \"no autodie\". To disable\nautodie for only a single function (eg, open) use \"no autodie qw(open)\".\n\n\"autodie\" performs no checking of called context to determine whether to throw an exception;\nthe explicitness of error handling with \"autodie\" is a deliberate feature.\n\nNo user hints defined for %s\nYou've insisted on hints for user-subroutines, either by pre-pending a \"!\" to the subroutine\nname itself, or earlier in the list of arguments to \"autodie\". However the subroutine in\nquestion does not have any hints available.\n\nSee also \"DIAGNOSTICS\" in Fatal.\n\nTips and Tricks\nImporting autodie into another namespace than \"caller\"\nIt is possible to import autodie into a different namespace by using Import::Into. However, you\nhave to pass a \"caller depth\" (rather than a package name) for this to work correctly.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "\"Used only once\" warnings can be generated when \"autodie\" or \"Fatal\" is used with package\nfilehandles (eg, \"FILE\"). Scalar filehandles are strongly recommended instead.\n\nWhen using \"autodie\" or \"Fatal\" with user subroutines, the declaration of those subroutines must\nappear before the first use of \"Fatal\" or \"autodie\", or have been exported from a module.\nAttempting to use \"Fatal\" or \"autodie\" on other user subroutines will result in a compile-time\nerror.\n\nDue to a bug in Perl, \"autodie\" may \"lose\" any format which has the same name as an autodying\nbuilt-in or function.\n\n\"autodie\" may not work correctly if used inside a file with a name that looks like a string\neval, such as eval (3).\n\nautodie and string eval\nDue to the current implementation of \"autodie\", unexpected results may be seen when used near or\nwith the string version of eval. *None of these bugs exist when using block eval*.\n\nUnder Perl 5.8 only, \"autodie\" *does not* propagate into string \"eval\" statements, although it\ncan be explicitly enabled inside a string \"eval\".\n\nUnder Perl 5.10 only, using a string eval when \"autodie\" is in effect can cause the autodie\nbehaviour to leak into the surrounding scope. This can be worked around by using a \"no autodie\"\nat the end of the scope to explicitly remove autodie's effects, or by avoiding the use of string\neval.\n\n*None of these bugs exist when using block eval*. The use of \"autodie\" with block eval is\nconsidered good practice.\n\nREPORTING BUGS\nPlease report bugs via the GitHub Issue Tracker at <https://github.com/pjf/autodie/issues>.\n",
            "subsections": []
        },
        "FEEDBACK": {
            "content": "If you find this module useful, please consider rating it on the CPAN Ratings service at\n<http://cpanratings.perl.org/rate?distribution=autodie> .\n\nThe module author loves to hear how \"autodie\" has made your life better (or worse). Feedback can\nbe sent to <pjf@perltraining.com.au>.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Copyright 2008-2009, Paul Fenwick <pjf@perltraining.com.au>\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This module is free software. You may distribute it under the same terms as Perl itself.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Fatal, autodie::exception, autodie::hints, IPC::System::Simple\n\n*Perl tips, autodie* at <http://perltraining.com.au/tips/2008-08-20.html>\n",
            "subsections": []
        },
        "ACKNOWLEDGEMENTS": {
            "content": "Mark Reed and Roland Giersig -- Klingon translators.\n\nSee the AUTHORS file for full credits. The latest version of this file can be found at\n<https://github.com/pjf/autodie/tree/master/AUTHORS> .\n",
            "subsections": []
        }
    },
    "summary": "autodie - Replace functions with ones that succeed or die with lexical scope",
    "flags": [],
    "examples": [],
    "see_also": []
}