The answer, IMHO, is that there is no if !
statement in Perl: There is an if
statement and there is a !
operator. The !
operator does not bind to if
; it operates on its argument. If you start thinking in these terms, your life will be easier.
So, in your case, you have,
do_something() unless something;
and
do_something() if something-else;
Let's put in the normally invisible parentheses:
do_something() unless ( something );
and
do_something() if ( something-else );
In this case, you tried to write something-else
so that the truth value of that condition is equivalent to the truth of something
, but failed to take into account the fact that !
operator binds tightly.
That is why there is not
.
Try
perl -ne 'print if not /^$/../^$/' file
See not
in perldoc perlop:
Unary not
returns the logical negation of the expression to its right. It's the equivalent of !
except for the very low precedence.