Search an Array [Perl]

I am newish to perl and am having difficulties writing a script to search an array from user input, I have no idea where to start :blush:

I have the basic code, just as an example


print("Please enter the users name: ");
$name = <STDIN>;
@names = ('Bob', 'Mary', 'June', 'David');

So if the name is found it would say “name found”, if it isn’t then it would say “name not found, names you can choose from are <names in the array”.

If someone could post and an example/or give any help it would be gratefully appreciated :slight_smile:

one way


print("Please enter the users name: ");
$name = <STDIN>;
chomp $name;
@names = ('Bob', 'Mary', 'June', 'David');
if (grep {$_ eq $name} @names) {
   print "found";
}
else {
   print "not found";
} 

Thanks Kevin!

Exactly what I was looking for :slight_smile: