in reply to Newbie flabbergasted by string compare results

Now I'm all flabbergasted. What's going on there? As it doesn't print the '0's, it seems the only thing that gives the right number of '1's is "Less than or equal to". Everything else seems to do something unexpected. What did I do wrong here?

The first answers correctly note the precedence issues. Your script does not print '0's because the boolean operators (i.e., everything except for cmp) are returning '' for the boolean false value.

To get around both issues, and learn about eval, try this instead:

#!/usr/bin/env perl use 5.012; use warnings; use strict; my @perm = ( [qw/a b/], [qw/b a/], [qw/a a/] ); for my $op (qw/cmp eq ne lt le gt ge/) { for my $expr (map { "'$_->[0]' $op '$_->[1]'" } @perm) { printf "%s == %s\n", $expr, eval($expr) eq '' ? "''" : eval($e +xpr); } }

Yes, I do the eval twice; normally I would avoid that, but here there is no side effect by design and the penalty is small.

Update: Add missing { back in. (Thanks Athanasius!)