Skip to content

Instantly share code, notes, and snippets.

@ExpandingShapes
Created October 26, 2020 09:03
Show Gist options
  • Save ExpandingShapes/0a437233e3d377d5abebd80a35aedc3b to your computer and use it in GitHub Desktop.
Save ExpandingShapes/0a437233e3d377d5abebd80a35aedc3b to your computer and use it in GitHub Desktop.
#!/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