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>