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

Re: pounding the smartmatch drum

Thread Previous | Thread Next
From:
Eric Brine
Date:
September 6, 2016 17:39
Subject:
Re: pounding the smartmatch drum
Message ID:
CALJW-qHK3_b+HGOZx4n892BHJNhQBvO9tPbrYUK30RBL1kPv4Q@mail.gmail.com
On Tue, Sep 6, 2016 at 10:51 AM, Paul "LeoNerd" Evans <
leonerd@leonerd.org.uk> wrote:

> Nicer would be if perl had notations for "try to call this method but
> if it doesn't exist, yield some sentinel falsey value like undef or
> empty list".


sub foo { my $invocant = shift; my $method = $invocant->can($method_name);
defined($method) ? $invocant->$method(@_) : () }

foo( $o, method_name => ( ... ) )

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