- 論壇徽章:
- 0
|
代碼如下,為何循環(huán)不能結(jié)束呢,read函數(shù)的說明文檔里也寫著 當(dāng)讀取完畢時(shí)返回值為0.無論是判斷返回值為0或者 undef 都不能結(jié)束循環(huán)。望高人指點(diǎn)。- 1 #!/usr/bin/perl
- 2 use IO::Socket;
- 3 use strict;
- 4 use constant BUFSIZE=>1024;
- 5 my $ip=$ARGV[0];
- 6 my $port=$ARGV[1]||11211;
- 7 my $sock=IO::Socket::INET->new(PeerPort=>$port,
- 8 PeerAddr=>"$ip",
- 9 Proto=>'tcp',)or die "can not connect to $ip\n$!";
- 10 my $data;
- 11 my $c;
- 12 print $sock "stats items\r\n";
- 13 while(1)
- 14 {
- 15 $c=read($sock,$data,BUFSIZE);
- 16 print $data;
- 17 last if $c==0;
- 18 }
- 19 exit;
復(fù)制代碼 |
|