Ville Jungman wrote:
>>Ville Jungman wrote:
>>Shortly, I think it might be good if loops (etc.) could return values.
>
> Yes, You're right John! A very good example! Which one would be more
> readable?
>
> This:
>> @bigger_than_4=
>> foreach $value(@values) {
>> retnext $value."a" if $value > 4;
>> }
>> ;
>
> ...or this:
>>@bigger_than_4 = grep { ( $_ = "${_}a" ) > 4 } @values;
i see where you are going and i do understand why you think your version
reads better especially if you (generally speaking) are new to Perl but
after you have used Perl for a while, grep and map become second nature and
the extra syntax becomes more annoying than useful. if you want better
communication for your code and the programmer, you might try something
like:
#!/usr/bin/perl -w
use strict;
sub four(&@){
my ($ref,@r) = shift;
for(@_){
my $s = eval &$ref;
push(@r,$s) if($s);
}
return @r;
}
my @r = four { q~ return $_ . "a" if($_ > 4) ~ } (2..7);
for(@r){
print "$_\n";
}
__END__
prints:
5a
6a
7a
you might find that more readable but it's really a mess. trust me: when you
get use to grep and map, you won't need what you propose.
david
--
$_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$";
map{~$_&1&&{$,<<=1,[EMAIL PROTECTED]||3])=>~}}0..s~.~~g-1;*_=*#,
goto=>print+eval
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]