#!perl -w use strict; use Socket; # for AF_UNIX, SOCK_STREAM, PF_UNSPEC use IO::Handle; # for autoflush and object constructor use IO::Select; # to demonstrate select()ability my $line; my $child = IO::Handle->new(); my $parent = IO::Handle->new(); socketpair($child, $parent, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "socketpair: $!"; my %names = ( $parent->fileno() => 'Parent', $child ->fileno() => 'Child', ); $child ->autoflush(1); $parent->autoflush(1); my $sel = IO::Select->new( $child, $parent ); $child ->print( "Hello, Parent\n" ); $parent->print( "Hello, Child\n" ); my @ready = $sel->can_read(0.1); print "There are ${\$sel->count} readable handles\n"; foreach my $ready ( @ready ) { my $name = $names{ $ready->fileno() }; print "$name receives: " . $ready->getline(); } $child->close(); $parent->close();