Modifying Permissions

The permissions on a file or directory define who (in broad categories) can do what (more or less) to that file or directory. Under UNIX, the typical way to change permissions on a file is with the chmod command. As a Windows user, you may be more used to the attrib command. Perl changes permissions with the chmod function. This operator takes an octal numeric mode and a list of filenames, and attempts to alter the permissions of all the filenames to the indicated mode. To make the files fred and barney with both read/write attributes, for example, do something like this:

chmod(0666,"fred","barney");

In short, the UNIX (and Perl) concept of file permissions consists of a bit for read, write, and execute rights for the user, the user’s group, and everyone else. These bits are combined to create the mode. Because Win32 systems have a significantly different concept of permissions, you don’t need to worry about all of the different possible values for the mode. Table 13.1 presents a couple of key values.

Table 13-1. Key Values for File Permissions

Mode

Meaning

0666

Read/Write

0444

Read only

Win32 systems determine whether or not a file is executable based on the file extension, so we’re not going to worry about the execute bits. Furthermore, even though some Windows NT filesystems support advanced user/group rights, the current Perl implementation doesn’t support access to these rights via chmod.

The return value of chmod is the number of files successfully ...

Get Learning Perl on Win32 Systems now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.