Don't be so smug. PHP has automatic iterators, bash shell scripts have it, C++ has it (though implemented in a completely different way, using lots of operator overloading), and there are probably lots more languages that have a similar construct.
Actually, this exact functionality is not suported by Perl, except for internal containers (ie, straight hashes and arrays, or tie'd versions thereof). I mean, this code:
my $container = Container->new(qw(e1 e2 e3));
foreach ($container) {
# now $_ is $container, NOT one of the elements in it
}
Is not equivalent to:
my @container = qw(e1 e2 e3);
foreach (@container) {
# now $_ iterates over the elements of @container
}
While in java 1.5 you CAN switch the container between a "full-blown" container object and a "basic" array.
The only remarkable thing about the implementation of this feature in Java, is that it wasn't there in Java 1.0 (probably because the standard container interfaces weren't introduced until 1.2 or thereabouts - big oversight by Sun, if you ask me).
Anyway, I don't think the introduction of a foreach-like construct in Java kan be considered an "acceptance of Perl leadership" whatever that means.
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.