Well, you might not do much better than that easily actually. The Dispatch table design pattern can help (you associate functions with some keys) which gives a basic example like that:
use strict; use warnings; use feature 'say'; my %operators = ( '>' => sub { $_[0] > $_[1] }, '==' => sub { $_[0] == $_[1] }); sub test { my ($op, $left, $right) = @_; die "Unknown operator: $op" unless exists $operators{$op}; say "$left $op $right" and return if $operators{$op}($left, $right); say "$right $op $left" if $operators{$op}($right, $left); } test "==", 1, 1; test ">", 2, 3; test ">", 4, 5; test "<", 6, 7; __DATA__ 1 == 1 3 > 2 5 > 4 Unknown operator: < at pm_1208722.pl line 12.
But if you want your own sentence to be written you'll need a more complex structure where for each key you have either several functions (one to compare, one to print) or a function and a template or something. I don't have the time to go any further than that at the moment though ^^".
In reply to Re: Passing logical operators on as content of scalar
by Eily
in thread Passing logical operators on as content of scalar
by gm40
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |