描述
该函数应在首次调用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 =
参考链接
https://www.learnfk.com/perl/perl-sethostent.html
标签:Addr,ip,无涯,Perl,62,print,sethostent,localhost From: https://blog.51cto.com/u_14033984/7086319