Skip to content

Instantly share code, notes, and snippets.

@jpf
Created May 26, 2009 20:40
Show Gist options
  • Select an option

  • Save jpf/118286 to your computer and use it in GitHub Desktop.

Select an option

Save jpf/118286 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
# Proof of concept for implementing boolean AND and OR logic in Nginx.
use strict;
my @truth_table = (
['0', '0', '1', '0'],
['0', '1', '0', '0'],
['0', '1', '1', '0'],
['1', '0', '0', '0'],
['1', '0', '1', '1'],
['1', '1', '0', '1'],
['1', '1', '1', '1'],
);
foreach my $test (@truth_table) {
my($a, $b, $c, $expected_result) = @{$test};
my $using_inline_logic = ($a && ($b || $c));
my $or = 0;
if($b) {
$or = 1;
}
if($c) {
$or = 1;
}
my $and = 0;
if($a) {
$and = $or;
}
my $using_if_logic = $and;
printf "%d == %d == %d\n", $expected_result, $using_inline_logic, $using_if_logic;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment