develooper Front page | perl.perl5.porters | Postings from March 2016

Re: Antw: Re: [perl #127684] operators '|||' and '&&&'

Thread Previous
From:
Abigail
Date:
March 14, 2016 14:41
Subject:
Re: Antw: Re: [perl #127684] operators '|||' and '&&&'
Message ID:
20160314144144.GA5773@almanda.fritz.box
On Thu, Mar 10, 2016 at 04:25:17PM +0100, Ulrich Windl wrote:
> >>> "Zefram via RT" <perlbug-followup@perl.org> schrieb am 10.03.2016 um 16:11 in
> Nachricht <rt-4.0.18-31775-1457622680-1028.127684-94-0@perl.org>:
> > Ulrich Windl wrote:
> >>It would be useful in the original context. I tired to make this a one-liner:
> >>    my $index_by_name = sub {
> >>        my $hi = $header_i{(shift)};
> >>
> >>        die unless (defined($hi));
> >>        return $hi;
> >>    };
> > 
> >     my $index_by_name = sub { $header_i{(shift)} // die };
> > 
> > This is a defined-or situation, not defined-and.
> 
> Thanks, I forgot "If no "return" is found and if the last statement is an expression, its value is returned." (wisdom from "man perlsub")


You don't even need that; it works with an explicit return as well:


    sub {return $header_i {+shift} // die}



Abigail

Thread Previous


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