Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

Comment on Tk failure
Download Code
Re: Tk failure
by Mr. Muskrat (Abbot) 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 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 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!";

    bbfu
    Black flowers blossom
    Fearless on my breath

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://270587]
Approved by Tomte
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2014-08-27 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls