【问题标题】:Perl : Bareword found where operator expectedPerl:在操作员预期的地方找到了裸字
【发布时间】:2014-04-02 08:55:51
【问题描述】:
#!/usr/bin/perl
use strict;
use warnings;

open(my $fh, '<', 'eg')
or die("Can't open fileC: $!\n");

while (<$fh>) {


perl -ne '($host, $port, @ip) = split /[=;.]/; print if $port != 50000+200*$i[2]+$ip[3]' eg;

}

在这段代码中我收到一个错误:

Bareword found where operator expected at qeg.pl line 15, near "'($host, $port, @ip) = split /[=;.]/; print if $port != 50000+200*$i[2]+$ip[3]' eg"
    (Missing operator before eg?)

【问题讨论】:

  • 发布真实脚本。和一些示例输入。
  • 您使用的是什么操作系统和外壳? Windows上的cmd.exe?还是在 Linux 上 bash?
  • 我正在使用 lunux Ubuntu。
  • 你在你的程序中启动了另一个 perl 并且做错了。如果你想启动另一个 perl 使用 ``

标签: perl


【解决方案1】:

替换

perl -ne '($host, $port, @ip) = split /[=;.]/; print if $port != 50000+200*$i[2]+$ip[3]' eg;

my ($host, $port, @ip) = split /[=;.]/;
print if $port != 50000+200*$ip[2]+$ip[3];

然后再试一次。

【讨论】:

  • 没有变量@i,所以应该是$ip[2]
猜你喜欢
  • 2011-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-16
  • 2023-03-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多