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

Re: feature 'switch' as an expression?

Thread Previous | Thread Next
From:
Paul Johnson
Date:
April 30, 2009 02:49
Subject:
Re: feature 'switch' as an expression?
Message ID:
20090430094926.GH8627@pjcj.net
On Thu, Apr 30, 2009 at 01:01:10AM -0700, Michael G Schwern wrote:

> 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.
> 
> Oh god, that's AWESOME!  I'm going to find an excuse to use that in production
> tomorrow.

It's even documented in perlop.  Rather unfortunately (IMHO), the
following wonderful line has been removed from that document:

  This is not necessarily guaranteed to contribute to the readability of
  your program.

-- 
Paul Johnson - paul@pjcj.net
http://www.pjcj.net

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