Copyright © tutorialspoint.com

PERL sethostent Function


Syntax

sethostent STAYOPEN


Definition and Usage

As gethostent() retriews the information for the next line in the host database, then sethostent sets (or resets) the enumeration to the beginning of the set of host entries. This function should be called before the first call to gethostent. The STAYOPEN argument is optional and unused on most systems.

Return Value

  • Nothing

Example

Try out following 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";
}

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;

Copyright © tutorialspoint.com