perl Can't use string Cxxx) as a symbol ref while "strict refs" in use at XXXX.pl错误

今天写脚本遇到Can't use string ("bond2     Link encap:InfiniBand ") as a symbol ref while "strict refs" in use at test.pl line 的错误函数

google了一下,发现stackoverflow有这样的错误,其中有一个是缺乏一个分号致使的google

例如:spa

open (FILE, "ifconfig | ");
while (<FILE>) 
{
        my $line = $_;
        print $line
        sleep 1;
}

运行以后是这个错误:code

Ifconfig is obsolete! For replacement check ip.
Can't use string ("bond2 Link encap:InfiniBand ") as a symbol ref while "strict refs" in use at test.pl line 15, <FILE> line 1blog

我仔细检查我本身的代码,并未发现缺乏分号,运行以后依然报错ip

个人代码是:就是运行data命令,把结果写到data.log中string

#!/usr/bin/perl
use strict;
sub TIME
{
        my $time=readpipe("date");
        return "$time\n";
}
open(TIME,">date.log") or die "$!\n";
print TIME &TIME;
close(TIME);

运行以后是这个样子pip

Can't use string (XXXXX) as a symbol ref while "strict refs" in use at test.pl line 8.class

并不是缺乏分号,我又仔细看了,发现函数名和文件句柄名都是TIME,就把文件句柄名改为别的,而后脚本就能够正常运行test

原来perl 文件句柄和函数不能使用相同的名字,之后再遇到相似的错误,注意检查一下文件名和分号

相关文章
相关标签/搜索