in reply to Re: creating tk buttons with for loop
in thread creating tk buttons with for loop

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.)