File::stat, Time::localtime and Time::gmttime

I've grouped these because they all basically do the same thing: they map an obtuse, list returning core function to a structure with named fields. None of these do anything that the core functions under them don't do, but they make for much, much more readable code:

 use Time::localtime;
 printf "Year is %d\n", localtime->year() + 1900;
 
 $now = ctime();

 use Time::localtime;
 use File::stat;
 $date_string = ctime( stat( $file )->mtime );

Time::localtime and Time::gmttime

Fields: sec, min, hour, mday, mon, year, wday, yday, and isdst

File::stat

Fields: dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksize, and block

...caveat...

User::pwent

 use User::pwent;
 $pw = getpwnam('daemon')       || die "No daemon user";
 if ( $pw->uid == 1 && $pw->dir =~ m#^/(bin|tmp)?\z#s ) {
     print "gid 1 on root dir";
 }

Fields: name, passwd, uid, gid, change, age, quota, comment, class, gecos, dir, shell, and expire

User::grent

 use User::grent;
 $gr = getgrgid(0) or die "No group zero";
 if ( $gr->name eq 'wheel' && @{$gr->members} > 1 ) {
     print "gid zero name wheel, with other members";
 } 

Fields: name, passwd, gid, and members

Links