Luke Palmer schrieb:
> That is not what it means in Python.
You trapped me. :) Actually I don't know any python but I've once read a
for/else construct in python. But obviously it doesn't dwIm.
>From the Python Reference Manual:
When the items are exhausted (which is immediately when the sequence
is empty), the suite in the else clause, if present, is executed,
and the loop terminates.
> I'm not sure about either interpretation, but admittedly Python's is
> harder to emulate clearly.
I'd like the For::Else behaviour more. Especially as I remember numerous
times writing an if clause to check if a list is empty before processing it.
I don't remember many cases where I wrote something like this:
my $found;
foreach my $item (@items) {
if ($item = 'foobar') {
$found = 1;
last;
}
}
unless ($found) {
..
}
To make it more clear, I could imagine (a subset of) this:
for @items -> $item {
say $item;
if $item == 42 {
say "I've found the Answer to Life, the Universe, and Everything!";
last;
}
} start {
say "Mh, I'll look for 42!"
} end {
say "The end has been reached. 42 not found."
} empty {
say "No items."
}
--
Thomas Wittek
http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]