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有这样的错误,其中有一个是缺少一个分号导致的

例如:

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

运行之后是这个错误:

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 1

我仔细检查我自己的代码,并未发现缺少分号,运行之后依然报错

我的代码是:就是运行data命令,把结果写到data.log中

#!/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);

运行之后是这个样子

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

并非缺少分号,我又仔细看了,发现函数名和文件句柄名都是TIME,就把文件句柄名改成别的,然后脚本就可以正常运行

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

 

转载于:https://www.cnblogs.com/tobecrazy/p/3668765.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值