2010-10-28 33 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確實有幫助,因爲它會發現上述錯誤。