in reply to A brain twister? (how to make 2 lines->1)
You can use the @{[ ... ]} construct.
$ perl -Mstrict -Mwarnings -E 'my %y = qw{c 3 d 4}; say "@{[%y]}";' c 3 d 4
The expression can be arbitrarily complex.
$ perl -Mstrict -Mwarnings -E 'my %y = qw{c 3 d 4}; > say "@{[join q{;} => map { $_ . q{=} . $y{$_} } sort { $b cmp $a } k +eys %y]}";' d=4;c=3
You can use a subroutine.
$ perl -Mstrict -Mwarnings -E 'sub z { reverse @_ } my %y = qw{c 3 d 4 +}; > say "@{[z(%y)]}";' 4 d 3 c
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A brain twister? (how to make 2 lines->1)
by perl-diddler (Chaplain) on Jun 25, 2012 at 10:43 UTC |