in reply to Code clarification - use of map and $$_

In your case, it's not $$_, but $$_[...]. The $$... is dereferencing a reference.

$$_[...] can be rewritten as $_->[ ... ], which might make the indexing of an array more obvious to you. See also References Quick Reference.

Replies are listed 'Best First'.
Re^2: Code clarification - use of map and $$_
by Anonymous Monk on Aug 09, 2016 at 17:25 UTC
    Collective huge thank you to everybody who contributed to this thread! Much to learn and read. Again: thanks!
Re^2: Code clarification - use of map and $$_
by Anonymous Monk on Aug 09, 2016 at 14:05 UTC
    Thanks for that. Why exactly would dereferencing be used here? Why not direct access to the variable?

      Because the list returned by @{$r{$k}} is a list of array references. On each iteration of the map loop one element is passed in from the array, @{$r{$k}}, to $_. That element is a reference to an array. Thus, to act upon its contents, you dereference it.


      Dave

      > Why exactly would dereferencing be used here? Why not direct access to the variable?

      without digging too deep into this code ...

      map can only iterate over scalars.

      I.e. like a list of $array_refs, if you want to address different arrays ...

      > Why not direct access to the variable?

      if you mean something like @array as the "direct" variable, you CAN'T do something like

      map { $_[0]++ } (@a,@b,@c)

      to increment the first element of each array.

      The real problem with that code is the laziness of the author to use a clear style.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      I don't know. Maybe ask the original author of the script.