Errno(3perl)

🌸 Errno β€” the errno constants, bestie πŸ’–

okay so this is Errno, from the Perl Programmers Reference Guide, and it's literally the cutest little module that gives you all your system errno constants. System errno constants, if we're being official. πŸŽ€


✨ SYNOPSIS ✨

use Errno qw(EINTR EIO :POSIX);

that's it. that's the whole vibe check. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea β˜• β€” Errno defines and conditionally exports every single error constant that's defined in your system's errno.h include file. all of them. she's thorough.

She's got one export tag, :POSIX, and that one will export all the POSIX defined error numbers. iconic behavior, no notes. πŸ‘‘

On Windows, Errno also defines and conditionally exports all the Winsock error constants defined in your system's WinError.h include file. Those cuties live in a second export tag called :WINSOCK. windows girlies stay winning. πŸͺŸβœ¨

Errno also makes %! magic, which is the part where it gets really fun. The way that works is: each element of %! has a non-zero value only if $! is set to that value. so %! is basically a lil lookup table for your current error. for example:

my $fh;
unless (open($fh, "<", "/fangorn/spouse")) {
    if ($!{ENOENT}) {
        warn "Get a wife!\n";
    } else {
        warn "This path is barred: $!";
    }
}

see how she did that? 😭 checking $!{ENOENT} instead of string-comparing the error message, we love a clean girl.

Now β€” if a specified constant EFOO does not exist on the system, then $!{EFOO} returns "". So if you wanna know whether the constant is even available on the system, you can use exists $!{EFOO} to check. πŸ•΅οΈβ™€οΈ

and the best part?? Perl automatically loads Errno the first time you use %!, so you don't need an explicit use. she just shows up. main character energy fr fr. πŸ’«


😭 CAVEATS 😭

ngl, importing a particular constant may not be very portable, because the import will fail on platforms that do not have that constant. like, it will just not work. 😬

So if you wanna be the portable, well-adjusted friend, a more portable way to set $! to a valid value is to use:

if (exists &Errno::EFOO) {
    $! = &Errno::EFOO;
}

check first, then assign. that's the move. 🫢


πŸ’œ AUTHOR πŸ’œ

Graham Barr <gbarr@pobox.com>


Copyright (c) 1997-8 Graham Barr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page bestie, ily, go forth and check your errnos πŸ’–πŸŒˆ β€” this was perl v5.44.0, dated 2026-10-17, and yes she's still serving Errno(3perl) after all these years. periodt. πŸ‘‘πŸ’…

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms