> > Haven't you heard? In perl 6, "for" will replace "foreach" and the
> > C-style "for" will be called "loop." Larry says that the C-style
> > "for" loop is used far less often than the "foreach" style. Sounds
> > like it's being deprecated...
>
> I've heard about this mythical perl6 thingy. Wasn't that the project
> Larry was going to write apocalypses about first, one for every chapter
> of the Camel? With 4 apocalypses in 1.5 years, 20 something chapters in
> the Camel, I'm not to focussed on perl6.
Give the man time! Perl 5 has been around for seven year (or more), so
what's wrong with it taking, err, seven years to write all the apocalypses?
Seriously, I can find 12 chapters worth anything in terms of difficultly,
lots of fringe features are going to be shifted into modules... like
low level IO, formats (bye bye rarely used feature), regex's (j/k) etc.
Most of these you wouldn't mind using a module for, as long as it was
part of the core. Many perl features are core, that don't need to be...
e.g. networking/unix permissions stuff. Removing these makes a far cleaner
language.
Maybe to awaken your interest, you should remember that Perl 6 may offer
great golfing oppertunity, since you'll be able to choose either Perl 5 or
Perl 6. This means that you could overtake Eugene or Lars or whoever has
taken the top spot... and the other 30 or so people above you by:
perl -5e'winning golf solution here'
isn't that going to be cruel, with many more oppertunities for varient
solutions.
> Let's deal with things that exist. Like perl5. Perl 5.8 certainly isn't
> marking 'for' as deprecated, so it won't disappear any sooner than 5.12.
> BTW, if Larry is going to rename 'for' to 'loop', then he plans to keep
> it around. Doesn't sound deprecated at all to me.....
'foreach' is really a workaround since 'for' was already taken. Larry
does some renaming, changes the behaviour a bit, and hey presto... making
loops of all kinds gets easier. This lovely snippet shows the most common
use of 'for' loop in Perl 5.
for 1 .. 100 -> $line {
print "$line: @array[$line]\n";
}
Now, that's definately more beautiful in my book, the 'foreach' style is:
foreach my $line (1 .. 100) {
print "$line: @array[$line]\n";
}
And in C style that would be:
for (my $line = 1; $line <= 100; $line++) {
print "$line: @array[$line]\n";
}
The new form of 'for' should allow setting multiple elements simutanously,
avoiding the need for:
my $line = 1;
foreach my $item (@data) {
$line++;
print "$line: $item\n";
}
To bring this back in topic... anyone propose to implement the
"Fisher-Yates shuffle" in Perl 6? (Or point me to the post it
was implemented... ). And I'm off to make sure Larry makes a
range operator able to decrement.
Jonathan Paton
__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com