Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
$test1 = ['A','D','B']; $test2 = ['A','C','B']; $source = ['A','B','C','A','B']; check_array($test1,$source); # Should return False # since "D" doesn't exist in # $source check_array($test2,$source); # Should return True # since all element exist in # $source check_array($test1,$source); sub check_array { my ($test,$source) = @_; OUT: foreach my $ts ( @{$test} ) { foreach my $sc (@{$source} ) { if ( $ts ne $sc ) { print "FALSE\n"; last OUT; } else { print "TRUE\n"; } } } return ; } Thanks beforehand.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Check if element in One Array Exist in Other Array
by gopalr (Priest) on Oct 13, 2005 at 06:18 UTC | |
|
Re: Check if element in One Array Exist in Other Array
by Ovid (Cardinal) on Oct 13, 2005 at 06:20 UTC | |
|
Re: Check if element in One Array Exist in Other Array
by graff (Chancellor) on Oct 13, 2005 at 06:44 UTC | |
|
Re: Check if element in One Array Exist in Other Array
by Rajeshk (Scribe) on Oct 13, 2005 at 07:41 UTC | |
|
Re: Check if element in One Array Exist in Other Array
by Skeeve (Parson) on Oct 13, 2005 at 06:10 UTC |