Rafa? Pocztarski wrote:
I forgot to cc: the list...
2009/12/10 Noah <noah-l...@enabled.com>:
I am hoping to figure out the best Way to write something. Â I have two
arrays @previous_hostnames and @hostnames.
I want to figure out if there is at least one matching element in
@previous_hostnames that is found in @hostnames.
You can use a lookup table to eliminate one loop:
my %previous_hostnames = map { $_ => 1 } @previous_hostnames;
for my $hostname (@hostnames) {
if ($previous_hostname{$hostname}) {
$found = 1;
last;
}
}
Or eliminate both loops:
my %previous_hostnames = map { $_ => 1 } @previous_hostnames;
my $found = @previous_hostnames{ @hostnames };
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/