I am getting this error when I use this code
sub search {
my ($a, @a_list) = @_;
foreach (@a_list) {
if($_ == $a) return TRUE;
# continue
Perl does not have built in constants for true and false. The canonical value for true is 1
and for false is ()
(which is an empty list in list context, and undef in scalar context).
A more idomatic way to write your code would be:
sub search {
my $key = shift;
foreach (@_) {
return 1 if $_ == $key;
}
return ();
}