V
Vorxion
If someone could please help me? I'm having issues with the <> operator.
I've read the docs on it, tried using close(ARGV), re-opening STDIN to "-",
and a slew of other things.
The upshot of this is that if I'm using <> and I supply @ARGV filenames,
Curses' wgetch() works fine. However, if I give input via STDIN instead,
I continuously get -1 on that function forever, which simply makes my
larger program unusable and entirely unresponsive.
Can anyone help, please? I've read up on eof(), perlop's section on <>,
and nothing is helping so far. I suspect it's possible, but it's gotta be
tricky, whatever the fix.
Sample code:
#!/usr/local/bin/perl
use strict;
use warnings;
$| = 1;
my @file_lines = <>; # Use filename in @ARGV, it's fine.
# Use a pipe or redirect, and getch()
# never works correctly.
use Curses;
initscr;
my $win = new Curses;
$win->clear;
$win->refresh;
$win->keypad(1);
noecho;
$win->addstr(0,0,"Enter keystroke: ");
$win->move(0,19);
$win->refresh;
while (my $keypress = $win->getch) {
$win->addstr(2,0,"Got key |${keypress}|.\n") if defined(${keypress});
}
endwin;
exit;
I've read the docs on it, tried using close(ARGV), re-opening STDIN to "-",
and a slew of other things.
The upshot of this is that if I'm using <> and I supply @ARGV filenames,
Curses' wgetch() works fine. However, if I give input via STDIN instead,
I continuously get -1 on that function forever, which simply makes my
larger program unusable and entirely unresponsive.
Can anyone help, please? I've read up on eof(), perlop's section on <>,
and nothing is helping so far. I suspect it's possible, but it's gotta be
tricky, whatever the fix.
Sample code:
#!/usr/local/bin/perl
use strict;
use warnings;
$| = 1;
my @file_lines = <>; # Use filename in @ARGV, it's fine.
# Use a pipe or redirect, and getch()
# never works correctly.
use Curses;
initscr;
my $win = new Curses;
$win->clear;
$win->refresh;
$win->keypad(1);
noecho;
$win->addstr(0,0,"Enter keystroke: ");
$win->move(0,19);
$win->refresh;
while (my $keypress = $win->getch) {
$win->addstr(2,0,"Got key |${keypress}|.\n") if defined(${keypress});
}
endwin;
exit;