Leser: 22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#!/usr/bin/env perl use warnings; use 5.012; use Time::HiRes qw(sleep); use Curses; initscr(); noecho(); cbreak(); nodelay( 1 ); sub done { endwin(); say "@_"; exit; } sub my_print { my @data = `ps aux 2>&1`; for my $i ( 0 .. $LINES - 1 ) { addstr( $i, 0, $data[$i] || ' ' x $COLS ); sleep 0.1; refresh(); } } my $timeout = 2; my_print(); while ( 1 ) { my ( $in, $out ) = ( '', '' ); vec( $in, fileno( STDIN ), 1 ) = 1; my $retval = select( $out = $in, undef, undef, $timeout ); if ( $retval == -1 ) { die "select-error"; } elsif ( $retval ) { while ( ( my $key = getch() ) ne ERR ) { done( "See ya" ) if $key eq 'q'; } } else { my_print(); } }
2011-02-22T15:24:16 kristianWas erwartest du in $retval?
Der Code:
if ( $retval == -1 )
scheint mir nicht "perlig"
perldoc -f selectOn error, "select" behaves like the select(2) system call : it returns -1 and sets $!.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/usr/bin/env perl use warnings; use 5.010; use Time::HiRes qw(sleep); use Curses; initscr(); noecho(); cbreak(); nodelay( 1 ); sub done { endwin(); say "@_"; exit; } sub my_print { my @data = `ps aux 2>&1`; for my $i ( 0 .. $LINES - 1 ) { addstr( $i, 0, $data[$i] || ' ' x $COLS ); sleep 0.1; refresh(); } } my $timeout = 2; my_print(); while ( 1 ) { select( undef, undef, undef, $timeout ); my_print(); }
1 2 3
my ($in, $out) = ('', ''); vec($in,fileno(STDIN),1) = 1; # look for key on stdin select($out = $in,undef,undef,$timeout);# wait up to this long