I am attempting to use arithmetic to evaluate the a function, which is written as a string:
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use feature 'say';
use autodie ':default';
my $str = '0.203580063041053 * $x + -0.0273785448865449';
my $x = 3;
my $ans = eval $str;
say $ans;
the above code works, and gives the correct answer.
However, perlcritic says that the above code is best avoided: Expression form of "eval" at line 10, column 11. See page 161 of PBP. (Severity: 5)
I have read that section of Perl's best practices, but it is very long, and I don't see how it applies to very simple situations like what I'm doing.
What is a good way of evaluating functions then?