Thread Korrekte Anwendung von select (7 answers)
Opened by Gast at 2011-02-22 11:36

Gast Gast
 2011-02-22 11:36
#145827 #145827
Habe ich hier "select" richtig angewandt?

Code (perl): (dl )
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();
        }
}

Last edited: 2011-02-22 11:44:38 +0100 (CET)

View full thread Korrekte Anwendung von select