{
    "mode": "perldoc",
    "parameter": "User::pwent",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/User%3A%3Apwent/json",
    "generated": "2026-05-30T06:07:39Z",
    "synopsis": "use User::pwent;\n$pw = getpwnam('daemon')       || die \"No daemon user\";\nif ( $pw->uid == 1 && $pw->dir =~ m#^/(bin|tmp)?\\z#s ) {\nprint \"gid 1 on root dir\";\n}\n$realshell = $pw->shell || '/bin/sh';\nfor (($fullname, $office, $workphone, $homephone) =\nsplit /\\s*,\\s*/, $pw->gecos)\n{\ns/&/ucfirst(lc($pw->name))/ge;\n}\nuse User::pwent qw(:FIELDS);\ngetpwnam('daemon')             || die \"No daemon user\";\nif ( $pwuid == 1 && $pwdir =~ m#^/(bin|tmp)?\\z#s ) {\nprint \"gid 1 on root dir\";\n}\n$pw = getpw($whoever);\nuse User::pwent qw/:DEFAULT pwhas/;\nif (pwhas(qw[gecos expire quota])) { .... }\nif (pwhas(\"name uid gid passwd\"))  { .... }\nprint \"Your struct pwd has: \", scalar pwhas(), \"\\n\";",
    "sections": {
        "NAME": {
            "content": "User::pwent - by-name interface to Perl's built-in getpw*() functions\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use User::pwent;\n$pw = getpwnam('daemon')       || die \"No daemon user\";\nif ( $pw->uid == 1 && $pw->dir =~ m#^/(bin|tmp)?\\z#s ) {\nprint \"gid 1 on root dir\";\n}\n\n$realshell = $pw->shell || '/bin/sh';\n\nfor (($fullname, $office, $workphone, $homephone) =\nsplit /\\s*,\\s*/, $pw->gecos)\n{\ns/&/ucfirst(lc($pw->name))/ge;\n}\n\nuse User::pwent qw(:FIELDS);\ngetpwnam('daemon')             || die \"No daemon user\";\nif ( $pwuid == 1 && $pwdir =~ m#^/(bin|tmp)?\\z#s ) {\nprint \"gid 1 on root dir\";\n}\n\n$pw = getpw($whoever);\n\nuse User::pwent qw/:DEFAULT pwhas/;\nif (pwhas(qw[gecos expire quota])) { .... }\nif (pwhas(\"name uid gid passwd\"))  { .... }\nprint \"Your struct pwd has: \", scalar pwhas(), \"\\n\";\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module's default exports override the core getpwent(), getpwuid(),\nand getpwnam() functions, replacing them with versions that return\n\"User::pwent\" objects. This object has methods that return the similarly\nnamed structure field name from the C's passwd structure from pwd.h,\nstripped of their leading \"pw\" parts, namely \"name\", \"passwd\", \"uid\",\n\"gid\", \"change\", \"age\", \"quota\", \"comment\", \"class\", \"gecos\", \"dir\",\n\"shell\", and \"expire\". The \"passwd\", \"gecos\", and \"shell\" fields are\ntainted when running in taint mode.\n\nYou may also import all the structure fields directly into your\nnamespace as regular variables using the :FIELDS import tag. (Note that\nthis still overrides your core functions.) Access these fields as\nvariables named with a preceding \"pw\" in front their method names.\nThus, \"$passwdobj->shell\" corresponds to $pwshell if you import the\nfields.\n\nThe getpw() function is a simple front-end that forwards a numeric\nargument to getpwuid() and the rest to getpwnam().\n\nTo access this functionality without the core overrides, pass the \"use\"\nan empty import list, and then access function functions with their full\nqualified names. The built-ins are always still available via the\n\"CORE::\" pseudo-package.\n",
            "subsections": [
                {
                    "name": "System Specifics",
                    "content": "Perl believes that no machine ever has more than one of \"change\", \"age\",\nor \"quota\" implemented, nor more than one of either \"comment\" or\n\"class\". Some machines do not support \"expire\", \"gecos\", or allegedly,\n\"passwd\". You may call these methods no matter what machine you're on,\nbut they return \"undef\" if unimplemented.\n\nYou may ask whether one of these was implemented on the system Perl was\nbuilt on by asking the importable \"pwhas\" function about them. This\nfunction returns true if all parameters are supported fields on the\nbuild platform, false if one or more were not, and raises an exception\nif you asked about a field that Perl never knows how to provide.\nParameters may be in a space-separated string, or as separate arguments.\nIf you pass no parameters, the function returns the list of \"struct pwd\"\nfields supported by your build platform's C library, as a list in list\ncontext, or a space-separated string in scalar context. Note that just\nbecause your C library had a field doesn't necessarily mean that it's\nfully implemented on that system.\n\nInterpretation of the \"gecos\" field varies between systems, but\ntraditionally holds 4 comma-separated fields containing the user's full\nname, office location, work phone number, and home phone number. An \"&\"\nin the gecos field should be replaced by the user's properly capitalized\nlogin \"name\". The \"shell\" field, if blank, must be assumed to be\n/bin/sh. Perl does not do this for you. The \"passwd\" is one-way hashed\ngarble, not clear text, and may not be unhashed save by brute-force\nguessing. Secure systems use more a more secure hashing than DES. On\nsystems supporting shadow password systems, Perl automatically returns\nthe shadow password entry when called by a suitably empowered user, even\nif your underlying vendor-provided C library was too short-sighted to\nrealize it should do this.\n\nSee passwd(5) and getpwent(3) for details.\n"
                }
            ]
        },
        "NOTE": {
            "content": "While this class is currently implemented using the Class::Struct module\nto build a struct-like class, you shouldn't rely upon this.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Tom Christiansen\n",
            "subsections": []
        },
        "HISTORY": {
            "content": "March 18th, 2000\nReworked internals to support better interface to dodgey fields than\nnormal Perl function provides. Added pwhas() field. Improved\ndocumentation.\n",
            "subsections": []
        }
    },
    "summary": "User::pwent - by-name interface to Perl's built-in getpw*() functions",
    "flags": [],
    "examples": [],
    "see_also": []
}