Ville Jungman wrote:
> 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.
use strict;
use warnings;
>
>
> @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)
>
> So, not very conserverite but think what all you could do with this.
> And please, let me know what you think about this. Crap?
Not crap, just unnecessary. If the loop should arrive at a value to be
returned, it should probably be enclosed in a function, which was designed for
returning values.
use strict;
use warnings;
my @values=(1,3,5,7);
my $value = get_first_value_bigger_than (4, @values);
print "$value\n";
sub get_first_value_bigger_than {
my ($limit, @values) = @_;
foreach (@values) {
return $_ if $_ > $limit;
}
}
Joseph
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]