Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Tk failure

by Lhamo_rin (Friar)
on Jul 01, 2003 at 18:20 UTC ( #270587=perlquestion: print w/replies, xml ) Need Help??
Lhamo_rin has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks, When I run the below portion of my script and the script cannot open the named directory it should run the Tk command under "unless" and then execute the exit command and leave the program. However, when I run, it leaves the program without running the Tk commands. I do not get any errors or warnings when executing the script. I am using warnings and diagnotics. Can anyone spot an error?
my $ep = 0; my $TEST = qx (read_apt _test_setup); chop $TEST; my $PATH = "/opt/adacs/test/$TEST/.saved_poins"; my $success = open RF, $PATH; unless ($success) { $ep = 1; my $fail = MainWindow->new(); $fail->geometry("250x150"); $fail->Label(-text => "File Failed To Open!")-> grid( $fail->Button(-text => "Acknowledge", - command => sub { exit})); } exit if $ep == 1;
Thanks, Lhamo_rin

Replies are listed 'Best First'.
Re: Tk failure
by ichimunki (Priest) on Jul 01, 2003 at 18:58 UTC
    Main problem is that you never call MainLoop().

    The following code does what you seem to want without the need for the $ep variable (and I didn't include the $TEST stuff because it's not relevant to the problem that I can see):
    use Tk; my $PATH = "/opt/adacs/test/$TEST/.saved_poins"; open( RF, $PATH ) or do_err_window() && exit; print "This got executed\n"; sub do_err_window { my $fail = MainWindow->new(); $fail->geometry("250x150"); $fail->Label(-text => "File Failed To Open!")-> grid( $fail->Button(-text => "Acknowledge", - command => sub { exit} ) ); MainLoop(); }
Re: Tk failure
by Mr. Muskrat (Canon) on Jul 01, 2003 at 18:56 UTC

    I assume that you do have use TK; somewhere in the rest of the script. So just add MainLoop; before the final closing curly brace.

Re: Tk failure
by bbfu (Curate) on Jul 02, 2003 at 18:36 UTC

    Shameless plug of Tk::Carp.

    use Tk::Carp qw/tkdie/; chomp(my $TEST = qx (read_apt _test_setup)); my $PATH = "/opt/adacs/test/$TEST/.saved_poins"; open RF, $PATH or tkdie "File failed to open!";

    Black flowers blossom
    Fearless on my breath

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://270587]
Approved by Tomte
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2017-10-23 07:00 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (277 votes). Check out past polls.