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

Re: feature 'switch' as an expression?

Thread Previous | Thread Next
From:
Ronald J Kimball
Date:
April 30, 2009 11:06
Subject:
Re: feature 'switch' as an expression?
Message ID:
20090430175837.GB26392@penkwe.pair.com
On Wed, Apr 29, 2009 at 09:11:43PM -0500, David Nicol wrote:

> Oh.  We /DO/ have ternary allowed as an l-value:
> $ perl -wle '( $result_goes_there ? $there : $here ) = get_result(); sub
> get_result { 27} print "h:$here";print "t:$there"'
> indicates that $here was set to 27 and $there was undefined.

This feature is of course documented in perlop:

   The operator may be assigned to if both the 2nd and 3rd arguments are
   legal lvalues (meaning that you can assign to them):

           ($a_or_b ? $a : $b) = $c;

Ronald

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