Perl sethostent 函数


描述

应在第一次调用 gethostent 之前调用此函数。STAYOPEN 参数是可选的并且在大多数系统上未使用。

当 gethostent() 检索主机数据库中下一行的信息时,sethostent 将枚举设置(或重置)到主机条目集的开头。

句法

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

sethostent STAYOPEN

返回值

该函数不返回任何值。

例子

以下是显示其基本用法的示例代码 -

#!/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