Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Code clarification - use of map and $$_

by Anonymous Monk
on Aug 09, 2016 at 14:05 UTC ( [id://1169405]=note: print w/replies, xml ) Need Help??


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

Thanks for that. Why exactly would dereferencing be used here? Why not direct access to the variable?
  • Comment on Re^2: Code clarification - use of map and $$_

Replies are listed 'Best First'.
Re^3: Code clarification - use of map and $$_
by davido (Cardinal) on Aug 09, 2016 at 14:56 UTC

    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

Re^3: Code clarification - use of map and $$_
by LanX (Saint) on Aug 09, 2016 at 14:55 UTC
    > 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!

Re^3: Code clarification - use of map and $$_
by Corion (Patriarch) on Aug 09, 2016 at 14:06 UTC

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1169405]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-25 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found