Perl chmod Function

Advertisements


Description

This function changes the mode of the files specified in LIST to the MODE specified. The value of MODE should be in octal. You must check the return value against the number of files that you attempted to change to determine whether the operation failed. This funcation call is equivalent to Unix Command chmod MODE FILELIST.

Syntax

Following is the simple syntax for this function:

chmod MODE, LIST

Return Value

This function returns Integer, number of files successfully changed.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl

$cnt = chmod 0755, 'foo', 'bar';
chmod 0755, @executables;
$mode = '0644'; chmod $mode, 'foo';      # !!! sets mode to # --w----r-T
$mode = '0644'; chmod oct($mode), 'foo'; # this is better
$mode = 0644;   chmod $mode, 'foo';      # this is best

When above code is executed, it produced following result:




Advertisements
Advertisements