in reply to Re: A brain twister? (how to make 2 lines->1)
in thread A brain twister? (how to make 2 lines->1)

Absolutely what I was looking for yours and the one above -- I don't know what I was doing wrong when I tried it ...oh, I remember, I was trying to use map directly with the hash -- thinking it would treat it as an array and I could get through the keys/values that way..., but map only works on array according to the manpage.

So then I started looking at the hash specific functions...

Too bad 'each' doesn't do what keys/values does -- I tried

@array=each %hash;, #and @array= [each %hash];...
but never got it to do what I wanted...sigh.

I've used map with values before, but was thinking there should be some way to do similar with 'each'...but each is just demented...1 item at a time...w/no slurp-ability......

And there I am with a straw trying to make it work...

Replies are listed 'Best First'.
Re^3: A brain twister? (how to make 2 lines->1)
by dave_the_m (Monsignor) on Jun 25, 2012 at 08:12 UTC
    but map only works on array according to the manpage
    No, map works on lists.
    but each is just demented...1 item at a time...w/no slurp-ability
    No, each fills a specific, useful niche. You are forgetting that a hash in list context returns its keys and values:
    @array=%hash;

    Dave.

Re^3: A brain twister? (how to make 2 lines->1)
by MidLifeXis (Monsignor) on Jun 25, 2012 at 13:00 UTC

    How about

    while (my ($key, $value) = each %hash) {...}

    See each for details. The example is directly from the documentation.

    --MidLifeXis