Paul LeoNerd Evans wrote:
> On Wed, 29 Apr 2009 16:33:44 -0400
> Mark Mielke <mark@mark.mielke.cc> wrote:
>
>> Seems like along that path would lie:
>>
>> my $x = if ($blah) { ... } else { 'foo' };
>
> Then while we're at it
>
> my @squares = foreach my $x ( @numbers ) { $x * $x };
> or
> my @squares = $_ * $_ foreach @numbers;
>
> (equivalent to map)
>
> my $prev = 0;
> my @primes = while( $prev < 100 ) { $last = gen_prime() };
> or
> my @primes = ( $_ = gen_prime() ) while $_ < 100;
>
> (no easy equivalent in perl)
I thought of a problem with all this.
sub foo {
for my $x (@_) {
$x + 2;
}
}
Right now that returns nothing. Change loops to return an expression and
suddenly its returning something. given/when is not so bad because it hasn't
been around very long to really have an impact. But changing if/for/while
will have a huge impact.
OTOH I'm having a hard time coming up with a practical situation where it
makes a difference.
--
170. Not allowed to "defect" to OPFOR during training missions.
-- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army
http://skippyslist.com/list/
Thread Previous
|
Thread Next