2010-10-28 34 views
1

错误:手指代码 - 不能执行

语法错误:文件意外

末下面是代码

我改变。

"#!/usr/local/bin/perl" 

实际的程序是

#!/local/perl5/bin/perl5.003 

use Socket; 

$sockaddr = 'S n a4 x8'; 

$host = $ARGV[0]; 
$them = $host; 
$port = 79; 
print "Finger $host: \n"; 
$hostname = ``; 
`nslookup $host |grep Name: >> $test`; 
print $test; 
#($name, $aliases, $proto) = getprotobyname('tcp'); 

($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^\d+$/; 
($name, $aliases, $type, $len, $thisaddr) = gethostbyname($hostname); 
$n1 = $name; 
($name, $aliases, $type, $len, $thataddr) = gethostbyname($them); 

$this = pack($sockaddr, &AF_INET, 0, $thisaddr); 
$that = pack($sockaddr, &AF_INET, $port, $thataddr); 

socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!"; 

bind(S, $this) || die "bind: $!"; 
connect(S, $that); 

select(S); $| = 1; select(stdout); 

print S "\n\n"; 

while (<S>) {print $_;}; 
+0

为了格式化您的代码,请选择它并在编辑框中按CTRL·K。为将来的问题。 – Benoit 2010-10-28 08:56:24

+0

谢谢你...将确保下次 – AAA 2010-10-28 08:58:28

+0

你不能使用比perl 5.003更好的东西吗?它在1996年发布。至于代码中的问题,$ test和$ proto从未初始化(原型被评论),整体事情似乎不稳定。你有没有尝试“perl -w foo.pl hostname”和“perl -d foo.pl hostname”?在调试中,使用“n”执行下一行并“print $ this”或“x @that”进行调查。 – 2010-10-28 09:17:57

回答

2

这里:

`nslookup $host |grep Name: >> $test`; 

$test在这一点上是不明确的,所以你问的shell执行nslookup whatever.com |grep Name: >>。 shell应该将输出重定向到哪里?

如果您将$test设置为某个文件名,如文件名......或者甚至是$test = "$host.txt";,它会让您更进一步。

与您的Perl版本无关,虽然能够use strict;use warnings确实有帮助,因为它会发现上述错误。