
$USE_NIS= 1;

sub getHosts {

my ($arefHosts, $arefFilters)= @_;

#------------------------------------------------------------------------------
# This function actually generates the list of hosts that match our
# filters.
#------------------------------------------------------------------------------

my ($regex)= '\b(' . join('|', @$arefFilters) . ')\b';

if ( $USE_NIS ) {
	open(HOSTS, "-|") || exec 'ypcat', 'hosts';
} else {
	open(HOSTS, '/etc/hosts') or warn "open: /etc/hosts: $!\n";
}

while(<HOSTS>) {
	s/#.*$//;
	next if ( /^\s*$/ );

	if ( /$regex/io ) {
		push(@$arefHosts, $1);
	}
}
close(HOSTS);

#------------------------------------------------------------------------------
# The end.
#------------------------------------------------------------------------------

}

1;
