Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hm, you can use map{}, but I don't know if that's really the best way to do it, depending on your actual requirement. If all you need to do is add '=>' to the beginning of each value in your %list hash, you can do this:

for (values %list) { $_ = '=>'.$_ }

If you need to keep the old list, you can always make a copy and do the above to the copy only.

If you really need to end up with an array of keys and values, you could do the above and then add one line:

my @arr = %list;

Just remember, while that will preserve key/value ordering, there is no guarantee about the order of the sets. In other words, a hash containing two pairs, 'one' => 1 and 'two' => 2 could result in two possible arrays: ( 'one',1,'two',2 ) or ( 'two',2,'one',1 ). The correct value will always follow the correct key, but that's about all you can guarantee (and that's always true when dealing with hashes).

All that said, it looks like you might be trying to put a hash into a form that can be saved and then read back later. If that's your goal, then (depending on the particulars), you might forego all of this for Storable or Data::Dumper.

Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
The Code that can be seen is not the true Code

In reply to Re: use of 'map' by radiantmatrix
in thread use of 'map' by Madam

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (3)
    As of 2020-06-04 17:11 GMT
    Find Nodes?
      Voting Booth?
      Do you really want to know if there is extraterrestrial life?

      Results (35 votes). Check out past polls.