It would be very easy for you share globals in your script, as others have pointed out. For simplicity, I would use Tk::ExecuteCommand to do the actual running of the commands. You can import your globals into it, and it forks off the commands automatically behind the scenes, so it won't block your gui. Of course, you can use threads, IPC::Open3, or piped opens also, but Tk::ExecuteCommand is pretty easy. I think it uses IPC::Open3 internally, so it may not work well on all win32 versions, but you didn't say what platform you are on.
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::ExecuteCommand; my $global = 'foobar'; my $mw = MainWindow->new; my $ec_dir = $mw->ExecuteCommand( -command => "echo $global; dir; sleep 5; dir;", -entryWidth => 50, -height => 10, -label => '', -text => 'Execute dir ', )->pack; my $ec_date = $mw->ExecuteCommand( -command => "echo $global; date; sleep 5; date;", -entryWidth => 50, -height => 10, -label => '', -text => 'Execute date ', )->pack; my $dir_but = $mw->Button( -text => 'Execute dir', -background => 'hotpink', -command => sub{ $ec_dir->execute_command })->pack; my $date_but = $mw->Button( -text => 'Execute date', -background => 'lightgreen', -command => sub{ $ec_date->execute_command })->pack; MainLoop;
Also, you can popup the execution widows, or hide them, depending on your needs. Tk::Execute::Command is good with subwidgets, so you can read the output textbox of each command, or change their colors, etc. The following example demonstrates that.
#!/usr/bin/perl -w use Tk; use Tk::ExecuteCommand; use strict; my $mw = MainWindow->new; #create and hide toplevel############ my $tl = $mw->Toplevel(); $tl->withdraw; my $snaptext = $tl->Scrolled('Text', -background=>'lightsteelblue', -foreground=>'black', )->pack(); $tl->Button(-text =>'Close', -command => sub{$tl->withdraw })->pack(); ####################################### my $ec = $mw->ExecuteCommand( -command => '', -entryWidth => 50, -height => 10, -label => '', -text => 'Execute', )->pack; my $dtext = $ec->Subwidget('text'); $dtext->configure( -background => 'black', -foreground => 'yellow', ); $mw->Button(-text => "Snap Shot", -command => sub{ my $time = localtime; my $old_y_view = $dtext->index('end'); print "$old_y_view\n"; my $gettext = $dtext->get('end -10 lines', 'end'); print "gettext->$gettext\n"; $snaptext->insert('end',"\n##$time\n$gettext\n###end $tim +e\n"); $snaptext->see('end'); $tl->deiconify; })->pack(); $ec->configure(-command => './test'); $ec->execute_command; MainLoop;

I'm not really a human, but I play one on earth. flash japh

In reply to Re: Method for sharing variables by zentara
in thread Method for sharing variables by diggernz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.