in reply to How to perform a subroutine run in cpan Tk::ExecuteCommand module

my $cmd = `&test($param1, $param2)` ;#Subroutine to be called by the T +k::ExecuteCommand button click

Backticks are not how you store a subroutine to be called later. See qx on what backticks actually do.

Did you try printing $cmd to find out what is actually contained in $cmd.

Most likely, you want to store a subroutine reference in $cmd:

my $cmd= sub { test($param1, $param2); };

Replies are listed 'Best First'.
Re^2: How to perform a subroutine run in cpan Tk::ExecuteCommand module
by Janish (Sexton) on Jun 25, 2014 at 07:44 UTC

    Thanks for your reply. I'm newbie, and yes, I tried to print out the $cmd, it print out nothing. Is that possible to call subroutine from the $ec->configure(-command => ) line?

    I wonder how people do if they want to execute external program which read wrapper (text in my case) with this module, as for now my end it only works with single liner command.

      Calling external programs is done by system or qx/backticks.

      If you want to call an external program when a button is clicked, put that call to the external program in your callback:

      my $cmd= sub { my $commandline= "my/external/program --foo=param1 --bar=param2"; system($commandline) == 0 or warn "Couldn't launch [$commandline]: $!/$?"; };

        I updated the code as you suggested, but yet it still doesn't work out for me. It now placing the random number "CODE(0x78efb0)" within the entry.

        I have updated my code as you suggested, but yet it still not work out for me. It is now placing a random generated number (CODE(0x78efb0) within the entry.