> Shortly, I think it might be good if
> loops (etc.) could return values.

BTW - One of the goals for Perl 6 is that you will be able to build any Perl
construct in Perl itself.

So also although Perl5, and probably Perl6, won't let you return values from
a loop, you should at least be able to build your own loop construct in Perl
6 that will.

Something to look forward to.

Rob

-----Original Message-----
From: Ville Jungman [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 8:25 PM
To: [EMAIL PROTECTED]
Subject: Should loops return a value?


Shortly, I think it might be good if loops (etc.) could return values.



Example 1: Retnext (like 'return next' borrowed from pl/sql)
You want to extract numbers from an array if they are > 4 and put an 
'a'-letter after them.

   @values=(1,3,5,7);
   @bigger_than_4=                           # get an array from loop
      foreach $value(@values) {
         retnext $value."a" if $value > 4;   # return value from loop if > 4
      }
   ;



Example 2: Retlast (== perl 'last'-command with a value)

You need to escape a loop with a value. Familiar way:

   while(<FH>){
      if(/stop/){
         $array_terminated='true';
         last;
      }
   }
   if($array_terminated){
      # something
   }

This could be written as:

   if(
      while(<FH>){
         retlast if /stop/;                  # returns $_ by default
      }
   ){
      # something
   }



So, not very conserverite but think what all you could do with this.
And please, let me know what you think about this. Crap?

---

ville jungman, 2 laureston crescent, tower, blarney, cork, ireland
tel. + 353 - 21 - 451 6847, http://www.kolumbus.fi/vilmak
usko Herraan Jeesukseen, niin sinä pelastut. (apt. 16:31)

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to