Beast am Dienstag, 16. August 2005 13.29: > I have these following arrays : > > @employees = (); # has 1000 elements > @managers = (); # has 100 elements > @staffs = (); # employees - managers > > I have @employees and @managers in hand, what is the most efficient ways > to print @staffs? > > So far this is what I've done. > ... > foreach my $emp (@employees) { > foreach my $mgr (@managers) { > if ($mgr eq $emp) { > print "$emp is Manager\n"; > } else { > print "$emp is Staff\n"; > } > } > } > ... > > As you can see, the step will increase as the number of manager increase.
I guess that avoiding the nested foreach loops by using a lookup hash would be at least faster (untested): # managers lookup hash my %managers=map {$_=>1} @managers; # select employees not in managers lookup hash my @staffs=grep { !exists $managers{$_} } @empoyees; (saving in @staffs could be omitted if printed directly) There may be a faster way, dunno. joe -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>