perlcritic is complaining with Expression form of "eval" [BuiltinFunctions::ProhibitStringyEval] on the first eval line from the code below:
use strict;
use warnings;
use feature qw/say/;
my $hasTwitter = 1;
my $validEmail = 0;
my $rule = '${hasTwitter} | ${validEmail}';
my $result = eval $rule;
say "Result -> $result";
$result = eval { $rule };
say "Result -> $result";
I tried to use eval {} to fix the perlCritic but then It does not return the expected result.
The response is:
Result -> 1
Result -> ${hasTwitter} | ${validEmail}
Is there a workaround using the string interpolation? The idea is to have a set of rules on a configuration file and let the code read and eval them.
Thanks
Perlcritic is not the ultimate authority. If you know what you're doing and why, just disable the given "sin" (either globally in the configuration, or by adding
## no criticto the offending line).In this case, you can use double quotes instead of single quotes and verify there are only zeros and ones in the resulting strings before evaluating them. Implementing a parser and evaluator of logic formulas is not that hard, either.