http://www.perlmonks.org?node_id=270587

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!";

    bbfu
    Black flowers blossom
    Fearless on my breath