Created
October 26, 2020 09:03
-
-
Save ExpandingShapes/0a437233e3d377d5abebd80a35aedc3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
my $num = 10; | |
my @arrWithNum = (1, 2, 3, 10, 9, 11, 12); | |
my @arrWithoutNum = (1, 2, 4, 5, 3, 8, 9); | |
sub Exists { | |
my $searchStatus = 0; | |
my $elem; | |
my ($x, @myArr) = @_; | |
foreach $elem (@myArr) { | |
if ($elem eq $x) { | |
$searchStatus = 1; | |
last; | |
} | |
} | |
return $searchStatus; | |
} | |
print Exists($num, @arrWithNum) . "\n"; | |
print Exists($num, @arrWithoutNum); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment