无涯教程-Perl - gethostent函数

51 阅读1分钟

描述

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

语法

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

gethostent

返回值

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

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

#!/usr/bin/perl

while( (name,name, aliases, addrtype,addrtype, length, @addrs)=gethostent() ) { print "Name =name\n";print"Aliases=name\n"; print "Aliases =aliases\n"; print "Addr Type =addrtype\n";print"Length=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 =

参考链接

www.learnfk.com/perl/perl-g…