IB2017 has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks
This is a basic question regarding calling subrutines with \& ... but I have problems in finding an answer. Given the Perl Tk code below (basically a file "dropper") I want to pass to the subrutine one more variable, in my example the dummy $SomeVariable. How can I achive it? And: where does the $selection in the subrutine comes from (it was not explicitally passed to it)? Thanks in advance to illuminate me.
#!/usr/local/bin/perl -w use Tk; use Tk::DropSite; use strict; use vars qw($top $drop); $top = new MainWindow; $top->Label(-text => "The drop area:")->pack; $drop = $top->Scrolled('Listbox', -scrollbars => "osoe", )->pack; my $SomeVariable="xxx"; $drop->DropSite (-dropcommand => [\&accept_drop, $drop], -droptypes => ($^O eq 'MSWin32' ? 'Win32' : ['KDE', 'XDND', 'Sun']) ); MainLoop; sub accept_drop { my($widget, $selection) = @_; my $filename; eval { if ($^O eq 'MSWin32') { $filename = $widget->SelectionGet(-selection => $selection, 'STRING'); } else { $filename = $widget->SelectionGet(-selection => $selection, 'FILE_NAME'); } }; if (defined $filename) { $widget->insert(0, $filename); } } __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calling subroutine with \& and passing variables
by Discipulus (Canon) on Oct 28, 2017 at 18:34 UTC | |
by IB2017 (Pilgrim) on Oct 29, 2017 at 01:48 UTC | |
by IB2017 (Pilgrim) on Oct 29, 2017 at 11:11 UTC | |
|
Re: Calling subrutine with \& and passing variables
by LanX (Saint) on Oct 28, 2017 at 18:28 UTC | |
by IB2017 (Pilgrim) on Oct 29, 2017 at 01:56 UTC | |
by LanX (Saint) on Oct 29, 2017 at 07:49 UTC |