Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello there,
I have a simple script to calculate the value of some test conditions on a database, that looks like below:
#!/usr/bin/perl use strict; use warnings; my %cTestH = (); my $dbFile = 'COUNTYDATABASE'; my $timeRng = 'DATERANGE'; my $regionName = 'DISTRICTNAME'; my $A = 'A'; my $B = 'B'; my $C = 'C'; $cTestH{$dbFile}{$timeRng}{$regionName}{$A} = 1; $cTestH{$dbFile}{$timeRng}{$regionName}{$B} = 0; $cTestH{$dbFile}{$timeRng}{$regionName}{$C} = 0; my $bool = 'A&!B&!C'; $bool =~ s/([a-zA-Z]\w*)/\$cTestH\{\$dbFile\}\{\$timeRng\}\{\$regionNa +me\}\{\$1\}/g; print "Evaluating Test Condition: ",$bool,'...',"\n"; print "Result is: ", eval($bool),"\n";
The value of the $bool should have been 1 but instead, Perl's eval function wrongly calculates the value of $bool as 0
What am I doing wrong?
Thank you.
-Layton
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Boolean Evaluation Shows Incorrect Results
by Tanktalus (Canon) on Mar 01, 2016 at 00:24 UTC | |
by Athanasius (Cardinal) on Mar 01, 2016 at 02:59 UTC | |
|
Re: Perl Boolean Evaluation Shows Incorrect Results
by dsheroh (Monsignor) on Mar 01, 2016 at 08:44 UTC |