Reputation: 25117
package My_Test;
use warnings;
use strict;
use Curses;
sub routine {
my $scr = newterm( $ENV{TERM}, \*STDERR, \*STDIN );
set_term( $scr );
noecho();
keypad( 1 );
printw "press a key: ";
refresh;
my $c = getch();
printw "$c\n";
refresh;
sleep 1;
endwin();
delscreen( $scr );
}
1;
When I run this script
#!/usr/bin/env perl
use warnings;
use strict;
use My_Test;
My_Test::routine();
My_Test::routine();
the second My_Test::routine
produces this error-message:
Use of uninitialized value in subroutine entry at My_Test.pm line 8.
argument 0 to Curses function 'set_term' is not a Curses screen at My_Test.pm line 8.
Why does this subroutine work only the first time?
Upvotes: 1
Views: 229
Reputation: 43683
package My_Test;
use strict;
use warnings;
use Curses;
our $scr = newterm($ENV{TERM}, \*STDERR, \*STDIN);
set_term($scr);
sub routine {
noecho();
keypad(1);
printw "press a key: ";
refresh;
my $c = getch();
printw "$c\n";
refresh;
sleep 1;
endwin();
}
1;
Upvotes: 1