So, you've posted the version that actually works as intended? No way for any of us to tell, since the code is, um, quite "personalized". Anyway, you might enjoy a few tricks for reducing the amount of repetition:
my %black_on_tan = (-fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my %black_on_yel = (-fg=>'black', -bg=>'yellow', -activebackground=>'yellow', -activeforeground=>'black'); # ... my $see_list=$w->Button(-text=>'See Deleted List', %black_on_tan); # likewise for other buttons...
Next, all those ugly regex tests on the output of "ps -ef | grep ..." can certainly be simplified -- look up the unix man page for "ps" to see how you can control what it prints, and just have it print the info you need. And, as with the attribute hash example above, assign the needed regex to a scalar variable, and use the scalar in your various "if" statements.

Alternatively, if this GUI is the only thing you use to start and stop the "check.pl" and "email.pl" scripts, try starting them like this, and avoid using ps altogether:

my %pid; # this should have global scope sub start_proc { my $proc = shift; # use one sub for both jobs return if ( $pid{$proc} ); # already set means it's running $pid{$proc} = fork; if ( $pid{$proc} == 0 ) { # true for the child process $path = ( $proc eq "email" ) ? $spam_dir : $check_dir; exec "perl $path/$proc.pl"; } # in the parent, $pid{$proc} is >0 } sub stop_proc { my $proc = shift; return unless ( $pid{$proc} ); `kill -9 $pid{$proc}`; $pid{$proc} = 0; }
I haven't tested that, and it may be inappropriate if these jobs have a tendancy to die unexpectedly, or are liable to be started from outside the GUI. But it should at least give some ideas about writing less redundant code.

(Actually, by starting the jobs with "fork", it becomes easier to check their status at any time afterwards, because you know what pid to look for -- e.g. you could use "ps -p $pid{$proc}", and just look for $pid{$proc} in its output -- if the pid doesn't show up there, it's not running.)


In reply to Re: Re: creating tk buttons with for loop by graff
in thread creating tk buttons with for loop by K_M_McMahon

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.