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

Re: feature 'switch' as an expression?

Thread Previous | Thread Next
From:
David Nicol
Date:
April 29, 2009 19:11
Subject:
Re: feature 'switch' as an expression?
Message ID:
934f64a20904291911v5123ecc2l1288b409feb3693e@mail.gmail.com
On Wed, Apr 29, 2009 at 4:24 PM, Graham Barr <gbarr@pobox.com> wrote:
>
> The value of a block has always been the value of the last statement
> executed.
> This is how subs get a default return value unless you explicitly do
> return;


Right.  So it's reasonable to expect  C< do { given ... } > to do what Hakim
expected.

By the way, you can fake up a ternary l-value by explicitly dereferencing
the result of the expression:

   ${ $result_goes_there ? \$there : \$here } = get_result();

I want ternary l-values!  C< ( $result_goes_there ? $there : $here ) =
get_result() > should work IMO, especially in a language that allows one to
do

   sub ifl : lvalue { $_[0] ? $_[1] : $_[2] }
   ifl($result_goes_there, $there, $here) = get_result();

... testing ...

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:$the
re"'
indicates that $here was set to 27 and $there was undefined.


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