目录

gethostent

描述 (Description)

此函数迭代主机文件中的条目。 它在列表上下文中返回以下内容 - ($name, $aliases, $addrtype, $length, @addrs)

语法 (Syntax)

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

gethostent

返回值 (Return Value)

此函数在错误上返回undef,否则在scalr上下文中返回主机名,在错误上返回空列表,否则在列表上下文中返回主机记录(名称,别名,地址类型,长度,地址列表)。

例子 (Example)

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

#!/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";
}

执行上述代码时,会产生以下结果 -

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  = 
↑回到顶部↑
WIKI教程 @2018