Larry Wall:
> :     if ($item = 'foobar') {

== of course ;)

> If you actually wrote that, then you'll always find that the first
> item has the value 'foobar'.  :)

> Well, leaving out the extraneous stuff, here's both kinds of "else" in one:
> 
>     $result = first 42, (@items || say "No items.")
>       err say "The end has been reached. 42 not found.";

That's a solution to find the first matching item.
But that's not the only reason to loop through a list.
"else" would be a general purpose solution.

> To get all of it in, you could use something more like:
> 
>     $result = first Any, gather for @items || say "No items." {
>       FIRST { 
>           say "Mh, I'll look for 42!"
>       }
>       when 42 {
>           say "I've found the Answer to Life, the Universe, and Everything!";
>           take $_;
>       }
>       LAST {
>           say "The end has been reached. 42 not found.";
>       }
>     }

That's, well, elegant! Yes.
Because and but it's tricky.
Nothing where I'd say "wow, thats an easy solution to my problem!".
It's a bit complicated, because you have to understand and combine
several concepts. That's elegant. But not easy, I think.
I think it's not simple enough for this simple kind of problem.

-- 
Thomas Wittek
http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]

Reply via email to