in reply to sockets and such in Perl
I think the issue you are sufferring from is that you want nonblocking IO, and you have blocking IO.
The first thing to do is to read MJD's article Suffering from Buffering?.
Once you get a handle on the issues involved, look into setting nonblocking IO modes on the filehandles of the sockets. This is an unwieldly task to get right - it takes a lot of fidgeting and fumbling, but eventually you start getting a feel for what's happenning.
Once you think you can solve it with nonblocking IO and select - stop. Don't do it. It's been done. Look into Event which can help you get callbacks for each named passed, and will allow you to read from the input of the file.
I think I also have a simpler solution, without any of these issues.
To translate to socketspace all you need is to replace STDIN/STDOUT with sockets opened to the right place.perl -pe1 file | \ perl -e 'open my $fh, "<", shift; my $line; FH: { $line = <$fh>; my $i +n; { $in = <STDIN>; redo if $in lt $line }; print $line if $line eq $ +in; redo }' | \ perl -e 'open my $fh, "<", shift; my $line; FH: { $line = <$fh>; my $i +n; { $in = <STDIN>; redo if $in lt $line }; if ($line eq $in) { print + $line; exit }; redo }'
Note that the code is untested.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sockets and such in Perl
by scotchfx (Sexton) on Jul 03, 2005 at 18:24 UTC | |
by nothingmuch (Priest) on Jul 03, 2005 at 19:27 UTC | |
by scotchfx (Sexton) on Jul 03, 2005 at 20:24 UTC | |
by nothingmuch (Priest) on Jul 04, 2005 at 03:39 UTC |