Hello, I tried your example, it worked as expected, here is the entire code:
--snip-- my @servers; my $each_server; my $each_host; my %seen = ( ); print "<h2>List of systems being performance monitored</h2>\n"; print "Please select a host\n"; opendir(RRDDIR,"/home/nagios/network-monitor/nagiosgraph/rrd") || die "Can't find servers"; @servers = readdir(RRDDIR); closedir RRDDIR; sub show_host{ my($each_host) = @_; my $thost; $each_host =~ /(.*)_(.*)_/; $thost = $1; $thost =~ s/\%2D/ /g; #print "$thost<BR>\n"; print "<option value=\"$thost\">$thost\n"; } print "<form name=serverlist action=layout.cgi method=GET>\n"; print "<select name=server size=10>\n"; foreach my $each_server(@servers) { unless ($seen{$each_server}) { $seen{$each_server} = 1; show_host($each_server); } } print "</select>\n"; print "</form>\n"; --snip-- On Wed, 2005-03-30 at 18:12 -0500, Offer Kaye wrote: > On Wed, 30 Mar 2005 15:53:25 -0700, Michael Gale wrote: > > > > But it is not working as expected, even if the array has the first three > > entries the same, the function "show_host" gets called three time ? > > > > foreach $each_server(@servers) > > { > > unless ($seen{$each_server}) { > > $seen{$each_server} = 1; > > show_host($each_server); > > } > > } > > > > The code is okay. Try just the following in a standalone file: > ########## begin code > use strict; > use warnings; > my @servers = qw/a a a b c d/; > my %seen; > foreach my $each_server(@servers) { > unless ($seen{$each_server}) { > $seen{$each_server} = 1; > show_host($each_server); > } > } > sub show_host { > print "$_[0]\n"; > } > ########## end code > If you run it, you will see it just prints "a" once, not 3 times. > So the problem is in some other code you are not showing us. > -- > Offer Kaye > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>