当我运行Perl脚本时,为什么会出现’use:command not found’?

前端之家收集整理的这篇文章主要介绍了当我运行Perl脚本时,为什么会出现’use:command not found’?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是Perl的新手.我已经使用一个论坛中的以下代码连接到其中一个服务器.但抛出错误信息

[root@Cus]# cat tt.pl
#!/usr/bin/perl
use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>2,Errmode=>'die');
$telnet->open('10.0.0.28');
$telnet->waitfor('/login:/');
$telnet->print('administrator');
$telnet->waitfor('/Password:/');
$telnet->print('test');
$telnet->waitfor('/switch8-12>/');
$telnet->print('whoamI');
$output=$telnet->waitfor('/switch8-12>/');
print $output;

但抛出以下错误消息.

[root@Cus]# ./tt.pl
./tt.pl: line 3: use: command not found
./tt.pl: line 4: Syntax error near unexpected token `('
./tt.pl: line 4: `$telnet = new Net::Telnet ( Timeout=>2,Errmode=>'die');'

解决方法

我的猜测是你正在使用一种不尊重#的奇怪的unix风格!线,并试图通过shell而不是通过perl运行脚本.

可能发生这种情况的另一个原因是tt.pl以空行开头. #!必须出现在文件的最开头.

尝试运行perl tt.pl并查看会发生什么.

猜你在找的Perl相关文章