Date sent: Tue, 19 Aug 2008 15:08:43 -0700 From: Noah <[EMAIL PROTECTED]> To: Perl Beginners <beginners@perl.org> Subject: searching arrays - more optimal code
> Hi List, > > Is there a more optimal way to present this data structure without > becoming completely convoluted? > > --- snip --- > > > for my $key (sort keys %usernames) { > my $found = 0; > for my $knownusername (@knownusernames) { > if ($knownusername eq $key) { > $found = 1; > } > } > print FIXTURE "*** Username $key is a configured and not > familiar\n" if ($found eq 1); > } > > ==== snip ---- The knownusernames shoul be a hash: my %knownusernames = map( ($_ => 1), @knownusernames); # or # my %knownusernames; @[EMAIL PROTECTED] = (); for my $key (sort keys %usernames) { print FIXTURE "*** Username $key is a configured and not familiar\n" if (exists $knownusernames{$key}); } HTH, Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/