2014-02-26 49 views
6

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

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

我能理解运用华侨城()如下面的perldoc例如:

$mode = "0644"; chmod(oct($mode), $tmp_file); 

但INT()函数?

编辑

只是为了完整性,这里是从的perldoc -f CHMOD推荐...

$mode = 0644; chmod $mode, "foo";  # this is best 

回答

10

它使绝对没有任何意义。 0664已经导致一个整数。

$ perl -MDevel::Peek -e'Dump(0664)' 
SV = IV(0x7a6118) at 0x7a6128 
    REFCNT = 1 
    FLAGS = (PADTMP,IOK,READONLY,pIOK) 
    IV = 436 

IOK表示标量包含整数值。

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

相关问题