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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.