As others have mentioned Perl5 doesn't (yet) have chained comparisons.
However if you are parsing "a < b <= c" from a config file and just want to evaluate it then perhaps this maybe what your steering after?
use strict;
use warnings;
use 5.010;
my ($a, $b, $c) = (10, 20, 30);
say 'Its true!' if comparison( $a, '<', $b, '<=', $c );
sub comparison {
my $left = shift;
while (my $cmp = shift) {
my $right = shift;
compare( $cmp, $left, $right ) or return;
$left = $right;
}
return 1;
}
sub compare {
my $op = shift;
given ($op) {
when ( '<' ) { return $_[0] < $_[1] }
when ( '<=' ) { return $_[0] <= $_[1] }
default { die "Invalid comparison operator" }
}
}
Its only a rudimentary example (ie. not complete and no error checking) but I think you get the idea.
And you may find something like this already on CPAN
. Something like Parse::RPN
maybe a useful building block.
Now if you question is about how to literally parse a < b <= c
then that is another kettle of fish!
/I3az/