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 文件句柄和函數不能使用相同的名字,之後再遇到相似的錯誤,注意檢查一下文件名和分號

相關文章
相關標籤/搜索