I want to create a subroutine of type grep {} @or map {} @that can handle code and / or logical input. Somehow on the Internet there is not much information about this.
I tried to create a sub below, but it can't even handle the first test. I get an error message Can't locate object method "BoolTest" via package "input" (perhaps you forgot to load "input"?) at C:\path\to\file.pl line 16..
How does it think this is an object? I do not create BoolTest correctly?
BoolTest { 'input' =~ /test[ ]string/xi };
BoolTest { $_ =~ /test[ ]string/xi } @array;
BoolTest(TRUE);
sub BoolTest
{
if ( ref($_[0]) == 'CODE') {
my $code = \&{shift @_};
if ($code->()) { say 'TRUE'; } else { say 'FALSE'; }
} else {
if ($_[0]) { say 'TRUE'; } else { say 'FALSE'; }
}
}
source
share