2009/12/10 John W. Krahn <jwkr...@shaw.ca>:
> Noah wrote:
>>
>> Hi there,
>
> Hello,
>
>> 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.
>
> my $found = map { my $x = $_; grep $x eq $_, @previous_hostnames }
> @hostnames;

Slightly more efficient is List::Util::first

use List::Util qw(first);
my $found = first { my $x = $_; grep {$x eq $_} @previous_hostnames }
@hostnames;

because this will stop as soon as the first element satisfying the
condition is found.

Phil

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to