I use configuration file to load logical expression which will later be replace with 0 or 1 depend on the success or failure
configuration
expression=(server.ip.1&&server.ip.2)||(server.ip.3&&server.ip.4)
Later server.ip.1 will replace with 1 or 0 depend on server availability. Later part of the logical expression evaluation has below piece of code.
my $reg_expression= configurator->get_reg_expression() ;
...
$reg_expression =~ s/$values[0]/$ip_status/g;
if ($reg_expression){
$logger->debug("no failover");
}else{
$logger->debug("falling to failover mode");
}
Issue is if condition always true what ever values assign to the expression. Issue seems to be it is taken as string so it always end up in true. Any other way that I can do the same or how can transfer above variable back to state where I can successfully use inside if condition.
$reg_expression = (0&&0)||(1&&0); # diffe
$reg_expression = '(0&&0)||(1&&0)';
You can use eval to evaluate the expression: