in reply to Re: wantarray alternative
in thread wantarray alternative
I'm really struggling to articulate my question. The real question is: If there's only one value in the return list, how can I return that value in scalar context, not the count of 1?.
sub lowercase { my @out = map { lc } @_ ; return @out == 1 && ! wantarray ? $out[0]: @out ; }
This code is optimized based on all the answers so far, and doesn't use first either. In fact, I've probably used this construction thousands of times.
My question is based on 3 assumptions:
I assumed that List::Util would include this functionality. That is, if first or some variant could determine and respond to the wantarray context.
UPDATE (no update)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: wantarray alternative
by LanX (Saint) on Jul 10, 2013 at 19:53 UTC | |
by tqisjim (Beadle) on Jul 10, 2013 at 20:22 UTC | |
by LanX (Saint) on Jul 10, 2013 at 20:24 UTC | |
by tqisjim (Beadle) on Jul 10, 2013 at 21:04 UTC | |
by LanX (Saint) on Jul 10, 2013 at 21:10 UTC | |
|
Re^3: wantarray alternative
by davido (Cardinal) on Jul 10, 2013 at 19:59 UTC | |
by tqisjim (Beadle) on Jul 10, 2013 at 20:35 UTC |