in reply to Adding an element of an array as a key for a Hash, and remaining elements as its value (would also be a hash)

wild guess

$MasterHash{$mvr} = { map { split /:/; } @array1 };
  • Comment on Re: Adding an element of an array as a key for a Hash, and remaining elements as its value (would also be a hash)
  • Download Code

Replies are listed 'Best First'.
Re^2: Adding an element of an array as a key for a Hash, and remaining elements as its value (would also be a hash)
by abhiram10 (Initiate) on Apr 12, 2016 at 02:16 UTC

    Thank you Monk! That totally worked. I guess I should have tried the curly braces! Thank you very much for pointing out. This really helps!

    The next question I have is how did this work and not the one I tried ? Could you please explain to me? There is something that I have to learn about these braces

      ... something that I have to learn about these braces

          $MasterHash{$mvr} = { map { split /:/; } @array1 };
                              ^     ^            ^         ^
                              |     |            |         |
                              |     + sub block  +         |
                              |                            |
                              + anon hash ref constructor  +
      See perlref for anonymous reference constructors (in particular, Making References section 3 for the anon hash ref constructor) and also perlreftut. See map for the function of the sub(routine) block.


      Give a man a fish:  <%-{-{-{-<

        Thank you very much AnomalousMonk. I will do some reading and understand deeper. This is very useful. I appreciate your time and efforts to explain it to me!

      also map in scalar context produces a count of the number of elements instead of the list of elements