I assume this is along the lines of what you were looking for?

use strict; use warnings; my %ahash=(one=>1, two=>2, three=>3, foo=>'$foo'); print join(", ", map { "'$_' => '$ahash{$_}'"} keys %ahash ), "\n"; __END__ 'three' => '3', 'one' => '1', 'foo' => '$foo', 'two' => '2'

Addendum: I've chosen to use single quotes for the output rather than double quotes, for the simple reason of keeping the output more or less copy/pastable (of course, copypastability gets lost as soon as a value is actually a reference, but if that is an issue I recommend something like Data::Dumper to you). Consider this template:

use strict; use warnings; my %ahash = ( # PASTE HASH CONTENTS BELOW ); print "'$_' => '$ahash{$_}', " for keys %ahash;
And you were to put in the output of my above script, it'd nicely print 'three' => '3', 'one' => '1', 'foo' => '$foo', 'two' => '2',. Had I used double quotes for the output of the original script and pasted its result into the template, I would've gotten some bothersome errors.
Global symbol "$foo" requires explicit package name at G:\x.pl line 6. Execution of G:\x.pl aborted due to compilation errors.

Why are array so much easier to print out than hashes...geez...
I beg to differ. Just remember to read elements in pairs.
use strict; use warnings; my %ahash=(one=>1, two=>2, three=>3); print join(", ", %ahash); __END__ three, 3, one, 1, two, 2


In reply to Re: A brain twister? (how to make 2 lines->1) by muba
in thread A brain twister? (how to make 2 lines->1) by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.