Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Stumped with select->can_read (example)

by tye (Sage)
on Aug 04, 2012 at 17:02 UTC ( #985445=note: print w/replies, xml ) Need Help??

in reply to Stumped with select->can_read

For example:

my $sel= ...; my $bytes= 16*1024; my %buf; my @ready; while( @ready= $sel->can_read() ) { foreach my $fh ( @ready ) { for my $buf ( $buf{$fh} ) { $buf = '' if ! defined $buf; my $eof= ! sysread( $fh, $buf, $bytes, length($buf) ); while( $buf =~ s/^(.*\n)// || $eof && $buf =~ s/^(.+)$// ) { my $line = $1; if( $line =~ /keyword/ ) { print REDUCEDLOG $line; } } } } }

- tye        

Replies are listed 'Best First'.
Re^2: Stumped with select->can_read (example)
by w1r3d (Initiate) on Aug 06, 2012 at 16:07 UTC

    Wow, awesome! I implemented that into my code, and that seems to work great! Thanks!

    I do have a question, though. I'm not sure what the line: "for my $buf ( $buf{$fh} )" is doing. Is the hash "%buf" getting initialized as the $buf variable gets populated with the sysread calls? That's the only line in the code that I'm struggling to understand. :/

    Thanks again!


      It just makes $buf an alias for $buf{$fh} so I don't have to type the {$fh} part over and over.

      - tye        

        Ah, makes sense. Thanks again =)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985445]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2017-12-14 01:09 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (382 votes). Check out past polls.