Not just eq/ne... but any expression that returns a true or false value — which implies: any expression in scalar context. (undef, "" and 0 are false, anything else is true.)
The generic variable $_ holds the value of the current item from the list. Actually, it's even stronger than that: $_ is an alias to the current item, which means: same value (by reference; you could say: same variable); different name. If you modify $_ in that expression, the original value will have changed. Example:
@original= (0 .. 5);
@true = grep $_*=2, @original;
local $" = ", "; # for nicely formatted output
print "original: @original\n";
print "output: @true\n";
Result:
original: 0, 2, 4, 6, 8, 10
output: 2, 4, 6, 8, 10
Each item in the original array has been doubled. Of those, only the nonzero (true) values have been come through the grep filter. |