develooper Front page | perl.perl5.porters | Postings from April 2009

Re: feature 'switch' as an expression?

Thread Previous | Thread Next
From:
Alberto Simões
Date:
April 29, 2009 13:35
Subject:
Re: feature 'switch' as an expression?
Message ID:
49F8BA0C.5050107@alfarrabio.di.uminho.pt
Hi

Mark Mielke wrote:
> Hakim Cassimally wrote:
>> I wanted to be able to write:
>>
>>     my $x = given ($blah) {
>>         ....
>>         default { 'foo' }
>>        }
>>
>> ...
>> Is there a way to work around this limitation?
>> And would it be worthwhile me submitting a docpatch to perlsyn?
>>   
> 
> Seems like along that path would lie:
> 
>    my $x = if ($blah) { ... } else { 'foo' };
> 

For the if construct you can always wrap it into an eval:

  my $x = eval { if ($blah) { ... } else { 'foo' }; }

Not sure if it works for switch (didn't try).


ambs
-- 
Alberto Simões - Departamento de Informática - Universidade do Minho
                 Campus de Gualtar - 4710-057 Braga - Portugal

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About