Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: wantarray alternative

by tobyink (Abbot)
on Jul 10, 2013 at 20:17 UTC ( #1043552=note: print w/ replies, xml ) Need Help??

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
Comment on Re: wantarray alternative
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043552]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2016-05-30 23:42 GMT
Find Nodes?
    Voting Booth?