Perl chmod Function



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.


Following is the simple syntax for this function −

chmod MODE, LIST

Return Value

This function returns Integer, number of files successfully changed.


Following is the example code showing its basic usage −


$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