Perl 设置函数


描述

应在第一次调用 getnetent 之前调用此函数。STAYOPEN 参数是可选的并且在大多数系统上未使用。当 getnetent() 从网络数据库中的下一行检索信息时,setnetent 将枚举设置(或重置)到主机条目集的开头。

句法

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

setnetent STAYOPEN

返回值

该函数不返回任何值。

例子

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

#!/usr/bin/perl

use Socket;

while ( ($name, $aliases, $addrtype, $net)  = getnetent() ) {

   print "Name = $name\n";
   print "Aliases = $aliases\n";
   print "Addrtype = $addrtype\n";
   print "Net = $net\n";
}

setnetent(1); # Rewind the database;

while ( ($name, $aliases, $addrtype, $net)  = getnetent() ) {

   print "Name = $name\n";
   print "Aliases = $aliases\n";
   print "Addrtype = $addrtype\n";
   print "Net = $net\n";
}

endnetent();  # Closes the database;

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

Name = default
Aliases = 
Addrtype = 2
Net = 0
Name = loopback
Aliases = 
Addrtype = 2
Net = 2130706432
Name = link-local
Aliases = 
Addrtype = 2
Net = 2851995648
Name = default
Aliases = 
Addrtype = 2
Net = 0
Name = loopback
Aliases = 
Addrtype = 2
Net = 2130706432
Name = link-local
Aliases = 
Addrtype = 2
Net = 2851995648
perl_function_references.htm