in reply to Calling subrutine with \& and passing variables

This means you are passing a callback, tk decides what is passed.

 (-dropcommand => [\&accept_drop, $drop],

Depending on what you want to achieve you can

you need to be clearer about your goal.

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

Replies are listed 'Best First'.
Re^2: Calling subrutine with \& and passing variables
by IB2017 (Pilgrim) on Oct 29, 2017 at 01:56 UTC

    Thank you for your reply. What I want to achive is actually quite simple: I'd like to pass the variable $SomeVariable to my subrutine to further process it (the code is a simplified version of my real code which is a quite complex GUI with many dynamically generated variables I need to process once the user has "dropped" a file into the widget).

    Hardcoding the variable in the subrutine doesn't seem to me viable as the variable is generated outside of it. Using a closure variable - as far as I understand - implies an "answer" from the subrutine (but I may be wrong about what a closure variable is). Inspecting the tk data structures hasn't helped me, unfortunately.

      Just use $SomeVariable inside your subroutine.

      Because it's declared outside with my it becomes a "closure variable".

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