First timer…so let me know if there is anything that I have not paid attention to whilst posing a question.
The question is how to use a scalar as a condition, as the code below does not work.
my @parameter=('hub');
my %condition;
$condition{'hub'}{'1'}='$degree>=5';
foreach (@parameter) {
if ($condition{$_}{'1'}) {..}
}
I thought that is because the condition is not interpreted correctly, so I also tried the following, which also did not work.
if ("$condition{$parameter}{'1'}") { ..}
Would really appreciate any help. 🙂
You either want string eval, which evaluates a string as Perl code
or perhaps a more secure approach would be using code references
In the second example, you are attaching a piece of code to a variable. The
$var->()syntax executes the code and evaluates to the return value of the code.