in reply to using grep to match more than two words
One can also play with one or more functions in List::MoreUtils.use strict; use warnings; my @source = qw(Sun Moon Pluto Venus Neptune); my @target = @ARGV ? @ARGV : qw(Sun Moon); print is_target_in_source(\@target, \@source), "\n"; sub is_target_in_source { my($target, $source) = @_; # omits arg validation my %target = map { $_ => 1 } @$target; my $in = 0; $target{$_} && $in++ for @$source; return $in == @$target ? 'Yes' : 'No'; }
But I found Array::Utils simpler to use:
Update: See also this FAQ entryuse strict; use warnings; use Array::Utils 'intersect'; my @source = qw(Sun Moon Pluto Venus Neptune); my @target = @ARGV ? @ARGV : qw(Sun Moon); my @in = intersect @target, @source; print @in == @target ? 'Yes' : 'No';
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
|
|---|