Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with output?

Status
Not open for further replies.

gammaman64

Programmer
Apr 28, 2007
9
US
I need the following segment of code to have the system look at the file which the user types into the entry widget. The only thing it does write now is store the click into a variable. I know it doesnot work because when executed there is no output on the dos window. Please help.

sub check {
my $check = $mw->DialogBox(
-background => 'red',
-title => 'Type the file you wish to check',
-buttons => [ 'OK', 'Cancel' ],
-default_button => 'OK',
);

my $txt;
my $entry = $check->Entry (
-textvariable => \$txt,
)->pack;

my $click = $check->Show();

return unless $click eq 'OK';

foreach $txt (@ARGV){

print ("Checking $txt\n");

if (-f $txt)
{


print ("The file $txt is:");
print ("readable")if(-r $txt);
print ("writable")if(-w $txt);
print ("executable") if (-x $txt);
}



elsif (-d $txt)
{
print ("$txt is a directory");


my @time = timeconv(-A $txt);
print "The file was last accessed at $time[0] days, ",
"$time[1] hours, $time[2] minutes ",
"and $time[3] seconds.\n";


}
}
}




sub timeconv{

my $time = shift();
my $days = int ($time);
$time = ($time - $days) * 24;
my $hours = int ($time);
$time = ($time - $hours) * 60;
my $minutes = int ($time);
$time = ($time - $minutes) * 60;
my $seconds = int ($time);
return ($days, $hours, $minutes, $seconds);

}
 
If you followed my tip on your other thread about tying STDOUT to a text widget, then print() does not show anything to the DOS window any more; everything it prints goes to that text widget.

Also:

Code:
   [COLOR=red]my $txt;[/color]
   my $entry = $check->Entry (
      -textvariable => \$txt,
   )->pack;

   my $click = $check->Show();
      
   return unless $click eq 'OK';

     foreach [COLOR=red]$txt[/color] (@ARGV){

You use the same variable name $txt here. This means that, the user types something into your dialog, which goes into $txt. But then when your foreach loop begins, $txt gets replaced by each of the elements in @ARGV in turn. At the end of this loop, $txt is not what the user typed in any more, it's now set to the last element of @ARGV, which is probably not what you want.

-------------
Cuvou.com | The NEW Kirsle.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top