Perl endhostent 函数



说明

此函数用于告诉系统,您不再希望使用 gethostent 从 hosts 文件读取条目。

语法

以下是此函数的简单语法 -

endhostent

返回值

此函数不会返回任何值。

示例

以下示例代码展示了其基本用法 -

#!/usr/bin/perl

while( ($name, $aliases, $addrtype, $length, @addrs) = gethostent() ) {
   print "Name  = $name\n";
   print "Aliases  = $aliases\n";
   print "Addr Type  = $addrtype\n";
   print "Length  = $length\n";
   print "Addrs  = @addrs\n";
}

sethostent(1);

while( ($name, $aliases, $addrtype, $length, @addrs) = gethostent() ) {
   print "Name  = $name\n";
   print "Aliases  = $aliases\n";
   print "Addr Type  = $addrtype\n";
   print "Length  = $length\n";
   print "Addrs  = @addrs\n";
}

endhostent();  # Closes the database;

当执行以上代码时,将产生以下结果 -

Name  = ip-50-62-147-141.ip.secureserver.net
Aliases  = ip-50-62-147-141 localhost.secureserver.net localhost.localdomain localhost
Addr Type  = 2
Length  = 4
Addrs  = 
Name  = ip-50-62-147-141.ip.secureserver.net
Aliases  = ip-50-62-147-141 localhost.secureserver.net localhost.localdomain localhost
Addr Type  = 2
Length  = 4
Addrs  = 
perl_function_references.htm
广告