Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Perl中-x选项的确切含义是什么_Perl_If Statement - Fatal编程技术网

在Perl中-x选项的确切含义是什么

在Perl中-x选项的确切含义是什么,perl,if-statement,Perl,If Statement,我不知道Perl,所以请耐心等待! 这是生成错误的脚本中的一位: if (-x '/usr/bin/gcc') { $gcc = Fink::Services::enforce_gcc(<<GCC_MSG); Under CURRENT_SYSTEM, Fink must be bootstrapped or updated with gcc EXPECTED_GCC, however, you currently have gcc INSTALLED_GCC

我不知道Perl,所以请耐心等待! 这是生成错误的脚本中的一位:

    if (-x '/usr/bin/gcc') {
        $gcc = Fink::Services::enforce_gcc(<<GCC_MSG);
Under CURRENT_SYSTEM, Fink must be bootstrapped or updated with gcc
EXPECTED_GCC, however, you currently have gcc INSTALLED_GCC selected.
This typically is due to alteration of symlinks which were
installed by Xcode. To correct this problem, you will need
to restore the compiler symlinks to the configuration that
Apple provides.
GCC_MSG
        $gcc = "-gcc" . $gcc;
    }
if(-x'/usr/bin/gcc'){

$gcc=Fink::Services::enforce_gcc(它测试文件是否设置了可执行位。 在您的情况下:
chmod-x/usr/bin/gcc
将导致您的
if
块不执行。
chmod+x/usr/bin/gcc
将导致
if
块执行。

Perl的文件测试操作符(您可以使用命令perldoc-f-x查看文档)通常遵循符号链接,但
-l
lstat()除外
。如果您特别想测试链接而不是目标,您可以先执行其中一项,然后测试
-x
-u
,因为参数会使它重用最后的统计结果。

-x
和friends只是标准函数,因此可以在以下内容中找到:“-x文件可以通过有效的uid/gid执行。”@wvxvw这是第一次发现的一个有点奇怪的构造:)另一个替代方案是
perlop
(也是标准perl文档的一部分)。@wvxvw然后提出一个新问题或改写现有问题。另外还有一个最小的测试用例是
-x
(在bash中)与
-x
(在perl中)如果它们与预期不符,那么就修改标题。一个好(或不好)的标题(或其他开场白)是多么令人惊讶可以创建或中断内容。@wvxw默认情况下,所有stat操作都遵循符号链接-也就是说,您正在测试链接指向的对象的属性,而不是链接本身。接受的答案是
它测试的是文件设置了可执行位。
。因此,这与我所说的相同(根据Perldoc)
-X  File is executable by real uid/gid