I have an array
my @array = qw/FOO BAR BAZ/;
and a scalar read from a file containing data like
That is exactly what grep is for. Here's a small snippet:
use strict;
use warnings;
my $str = "+++123++585+++FOO";
my $blank = "+++123++585+++XYZ";
my @array = qw/FOO BAR BAZ/;
print grep {$str =~ $_} @array, "\n";
print grep {$blank =~ $_} @array, "\n";
This would just return:
FOO
grep
, reduce
and map
are what we call higher order functions in FP world, though reduce
might be called fold
there. Have a look at MJD's Higher Order Perl for more of these.