perl - 为什么在 Perl chmod 中使用 int()?

标签 perl chmod

为什么在 Perl 中设置文件的权限时需要使用 int() 函数?

die "blab, blah"
    if (! chmod(int(0664), $tmp_file));

我可以理解 oct() 的使用,如下面的 perldoc 示例所示:
$mode = "0644"; chmod(oct($mode), $tmp_file);

但是 int() 函数呢?

编辑

为了完整起见,这里是 perldoc -f chmod 的建议...
$mode = 0644;   chmod $mode, "foo";      # this is best

最佳答案

这完全没有意义。 0664已经产生一个整数。

$ perl -MDevel::Peek -e'Dump(0664)'
SV = IV(0x7a6118) at 0x7a6128
  REFCNT = 1
  FLAGS = (PADTMP,IOK,READONLY,pIOK)
  IV = 436
IOK表示标量包含一个整数值。

这肯定是某人以 oct("0644") 开头的结果但不太了解当他们不再使用字符串时他们在做什么。

关于perl - 为什么在 Perl chmod 中使用 int()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22046186/

相关文章:

linux - 如何在 Linux 中终止后台 while 循环?

linux - 非常简单的 perl 脚本有大量内存泄漏

php - Laravel 5.2 无法打开 laravel.log

c - C 中的 fchmod 函数

使用c在linux中创建具有给定名称和权限的文件

linux - Unix 权限 : different chmod on folder and its files

arrays - Perl:为什么 for 和 foreach 给出不同的结果?

perl - 是否有搜索多余代码的模块?

perl - 覆盖在模块中定义但在其运行时阶段使用之前的函数?

linux - 如何将文件权限授予组中的特定用户?