#!/usr/bin/env perl use strict; use warnings; # Also, see Interactive Client with IO::Socket for another # demonstration at: http://perldoc.perl.org/perlipc.html pipe( my $p_rdr, my $c_wtr ); pipe( my $c_rdr, my $p_wtr ); autoflush $c_wtr, 1; autoflush $p_wtr, 1; my $pid = fork() // die "can't fork: $!"; if ( $pid ) { # parent process my $reply; while ( defined ( $reply = <$p_rdr> ) ) { last if ( length $reply == 1 ); print $p_wtr "Hello, $reply"; } waitpid $pid, 0; } else { # child process my $reply; my @names = qw/ Sun Moon Wind Air /; for my $name ( @names ) { print $c_wtr "$name\n"; $reply = <$c_rdr>; print $reply; } print $c_wtr "\n"; exit 0; } #### Hello, Sun Hello, Moon Hello, Wind Hello, Air