Perl gethostent 函数
描述
此函数迭代主机文件中的条目。 它在列表上下文中返回以下内容 − ($name, $aliases, $addrtype, $length, @addrs)
语法
以下是此函数的简单语法 −
gethostent
返回值
此函数在错误时返回 undef,否则在 scalr 上下文中返回主机名,在错误时返回空列表,否则在列表上下文中主机记录(名称、别名、地址类型、长度、地址列表)。
示例
以下是显示其基本用法的示例代码 −
#!/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 =

