in reply to Re^3: How to perform a subroutine run in cpan Tk::ExecuteCommand module
in thread How to perform a subroutine run in cpan Tk::ExecuteCommand module

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.

  • Comment on Re^4: How to perform a subroutine run in cpan Tk::ExecuteCommand module

Replies are listed 'Best First'.
Re^5: How to perform a subroutine run in cpan Tk::ExecuteCommand module
by Corion (Patriarch) on Jun 25, 2014 at 08:16 UTC

    I'm sorry - I had not read the documentation for Tk::ExecuteCommand.

    $cmd is only allowed to be a shell command. So you can only use the following:

    my $cmd= "/nfs/work/testing123.pl -text text"; $ec->configure( -command => $cmd ); $ec->update;

    Note the double quotes instead of the backticks.

      Thanks Corion, By putting the whole execution line in $cmd, it works, but what I'm looking for is if the module can works on subroutine instead of a command. As there and something else extra I would like to put inside the subroutine before the one liner external command be executed. The Perl external script is part of the job inside my subroutine. Can this be done?

        Not directly with that module.

        I don't use Tk, so I don't really know alternatives to that, but I assume that you can look at the source code and adapt it so your callback gets run in a fileevent callback for the handle to the child process.

        I could not find a widget that does what you ask, but

        Try [meatacpan://Tk::Text]

        I think something like:

        sub do_something { ... } sub do_something_else { ... } my $result = do_something; $tw->Insert($result); $result = do_something_else; $tw->Insert($result);

        should do what you want.

        Tk::Text::Insert inserts the supplied text at the insertion point. I think it advances the insertion point, so repeated calls will append to what was inserted by the previous call.

        This will accumulate text until Perl runs out of resources or you stop adding more text. There are methods to delete text from the widget.

        Alternately, you could maintain the text you want to display in your own variable, then update the widget as needed:

        $tw->Contents($textToDisplay);