UPDATE: Well, I don't know for sure if it was the additon of the my because I found some other errors too, but the whole thing works as planned now!
THANX!!

I was working on another computer at the time so I didn't have the whole code with me, I typed in the part that I had a problem with. I will post the entire code here.
#!/usr/bin/perl # # #use strict; use Tk; use Tk::Scrollbar; use Tk::Text::SuperText; my $check_dir="/home/Kevin/Desktop/ip"; my $spam_dir="/home/Kevin/Desktop/spam"; my $i=0; my $w=new MainWindow; $w->geometry('300x450'); $w->geometry('+0+0'); $w->title("Kevin's Script Control Center"); #$w->Label(-text=>"Kevin's Script Control Center")->pack; my $see_list=$w->Button(-text=>'See Deleted List', -command => sub{&see_list}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $open_curr=$w->Button(-text=>'Open Current Deleted', -command => sub{&open_curr}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $quit=$w->Button(-text=> 'Quit', -command => sub{exit}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $start_check=$w->Button(-text=> 'Start', -command=>sub{&start_check}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $stop_check=$w->Button(-text=> 'Stop', -command=>sub{&stop_check}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $start_email=$w->Button(-text=> 'Start', -command=>sub{&start_email}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $stop_email=$w->Button(-text=> 'Stop', -command=>sub{&stop_email}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $status_check=$w->Button(-text=> 'NO STATUS', -fg=>'black', -bg=>'yellow', -activebackground=>'yellow', -activeforeground=>'black'); my $status_email=$w->Button(-text=> 'NO STATUS', -fg=>'black', -bg=>'yellow', -activebackground=>'yellow', -activeforeground=>'black'); my $email_label=$w->Label(-text=>'EMAIL.PL'); my $check_label=$w->Label(-text=>'CHECK.PL'); $w->repeat(1000,sub{&status_check}); $see_list->place(-x=>90,-y=>360); $open_curr->place(-x=>75,-y=>390); $check_label->place(-x=>125,-y=>25); $email_label->place(-x=>125,-y=>90); $status_email->place(-x=>125,-y=>120); $stop_email->place(-x=>220,-y=>120); $start_email->place(-x=>30,-y=>120); $status_check->place(-x=>125,-y=>60); $start_check->place(-x=>30,-y=>60); $stop_check->place(-x=>220,-y=>60); $quit->place(-x=>125,-y=>425); &MainLoop; sub status_check { my @temp=`ps -ef | grep check.pl`; foreach (@temp) { if (($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2}\s ++pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check.pl +/)||($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+pts\/2\ +s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check.pl/)) {$check=1;} } if (($check)==1) { $status_check->configure(-bg=>'green', -activebackground=>'green', -text=>'UP'); } else { $status_check->configure(-bg=>'red', -activebackground=>'red', -text=>'DOWN'); } my @temp=`ps -ef | grep email.pl`; foreach (@temp) { if (($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2}\s ++pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/email. +pl/)||($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+pts\/ +2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/email.pl/)) {$email=1;} } if (($email)==1) { $status_email->configure(-bg=>'green', -activebackground=>'green', -text=>'UP'); } else { $status_email->configure(-bg=>'red', -activebackground=>'red', -text=>'DOWN'); } undef($email); undef($check); } sub start_check { my @temp=`ps -ef | grep check.pl`; foreach (@temp) { if (($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2}\s ++pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check.pl +/)||($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+pts\/2\ +s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check.pl/)) {$already=1;} } if ($already!=1) {system("perl $check_dir/check.pl &");} undef($already); } sub stop_check { my @temp=`ps -ef | grep check.pl`; foreach (@temp) { if (($_=~/^kevin\s+(\d{1,5})\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2} +\s+pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check. +pl/)||($_=~/^kevin\s+(\d{1,5})\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+pts +\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check.pl/)) {$pid=$1;} } if (defined($pid)){system("kill -9 $pid");} undef($pid); } sub start_email { my @temp=`ps -ef | grep email.pl`; foreach (@temp) { if (($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2}\s ++pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/email. +pl/)||($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+pts\/ +2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/email.pl/)) {$already=1;} } if ($already!=1) {system("perl $spam_dir/email.pl &");} undef($already); } sub stop_email { my @temp=`ps -ef | grep email.pl`; foreach (@temp) { if (($_=~/^kevin\s+(\d{1,5})\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2} +\s+pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/emai +l.pl/)||($_=~/^kevin\s+(\d{1,5})\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+p +ts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/email.pl +/)) {$pid=$1;} } if (defined($pid)){system("kill -9 $pid");} undef($pid); } sub open_curr { @right_now=gmtime(); $curr_doy=$right_now[7]+1; $filename="$spam_dir/deleted.$curr_doy"; my $new=$w->Toplevel; $new->title("Current Deleted List"); $open_curr=$new->Scrolled("Text")->pack(-side=>'bottom', -fill=>'both',-expand=>1); open(FH,"$filename"); while(<FH>) {$open_curr->insert("end",$_);} close(FH); } sub see_list { my %temp_see_list; opendir(SPAM,$spam_dir); my @files=readdir(SPAM); close(SPAM); my @deleted=grep(/^deleted/,@files); my $new=$w->Toplevel; $new->title("List of Deleted Files"); foreach my $open (@deleted) { $temp_see_list{$open}=$new->Button(-text=> "$open", -command=>sub{&view("$spam_dir/$open")}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red')->pack; } } sub view { ($file)=@_; my $newer=$w->Toplevel; $newer->title("$file Listing"); $open_this=$newer->Scrolled("Text")->pack(-side=>'bottom', -fill=>'both',-expand=>1); open(FH,"$file"); my @temp=<FH>; close(FH); foreach $line (@temp) {$open_this->insert("end",$line);} }


I also included the second suggestion to add the my into the for loop itself, same result. It names the button properly, but it doesn't pass the argument to the subroutine VIEW.

-Kevin

In reply to Re: creating tk buttons with for loop by K_M_McMahon
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.