http://www.perlmonks.org?node_id=1043552


in reply to wantarray alternative

This is quite a concise way of doing things:

sub lowercase { wantarray ? (map { lc } @_) : lc(shift); }

This is an insane way of doing things:

sub lowercase { ( wantarray ? sub{@_} : sub{shift} )->( map { lc } @_ ); }

Update: Here's another solution using my module returning that allows you to create additional keywords that act like return...

#!/usr/bin/env perl use v5.14; use returning { lreturn => sub { wantarray ? @_ : $_[0] } }; sub lowercase { lreturn map { lc; } @_; warn "this line never executes"; } say for lowercase('Alice', 'Bob'); say scalar lowercase('Carol', 'Dave');
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name