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
    Well, not that I need the whole problem solved, but it was important to me to be able to print the hashes in hash format -- meaning they'll be bracketed with {} and have => between key/values, a strictly comma separated list defeats the purposes.

    maybe using an embedded foreach w/each, since it seems like most of the above solutions lose the *visual* pairing.

    (I also print out arrays in x, y, z form, and just wanted my hashes to look hashy!...

    then again maybe just looping through using map & keys might be sufficient...only 400 ways to do this, just finding the 'right' one...that generates the correct output... ;-)