#! /usr/bin/perl # not_vs_! illustrates the difference in effect caused by operator precedence use strict; use warnings; explore (' if (not $foo && $bar ne "") {1;} ', ' if ((not $foo) && ($bar ne "")) {1;} '); explore (' if (! $foo && $bar ne "") {1;} ', ' if ((! $foo) && ($bar ne "")) {1;} '); sub explore { foreach my $expr (@_) { print "\nExpression $expr\n"; print "foo bar !foo bnn result \n"; foreach my $foo (0, 1) { my $nfu = (not $foo); foreach my $bar ("", 1) { my $bnn = ($bar ne ""); my $result = eval "$expr"; printf "%2s%4s%5s%5s%4s\n",$foo, $bar, $nfu, $bnn, $result ; } } } } # not_vs_! Ends