#!/usr/bin/perl print "What is your name?\n"; my $name = prompt_for_input(); print "What is your mission?\n"; my $mission = prompt_for_input(); print "What is your favorite color?\n"; my $color = prompt_for_input(); print "Your name is $name, your mission is $mission, and your favorite color is $color. Have a nice day!\n"; sub prompt_for_input { local ($|) = (1); my $resp = ; chomp $resp; return $resp; } #### #!/usr/bin/perl use strict; use warnings; use diagnostics; use IPC::Open3; use IO::Select; my @answers = qw/galahad seekthegrail bluenored!/; my( $wtr, $rdr, $err ); use Symbol 'gensym'; $err = gensym; my $pid = open3( $wtr, $rdr, $err, 'server.pl' ); print "IN: $wtr OUT: $rdr ERR: $err\n"; print "PID was $pid\n"; my $sel = new IO::Select; $sel->add( $wtr, $rdr ); my $line; foreach my $readhandle ( $sel->can_read(1) ) { print "readhandle is $readhandle \n"; next if $readhandle != $rdr; print "past next\n"; my $len = sysread $readhandle, $line, 4096; if( not defined $len ) { die "Error from child: $!\n"; } print $line; write_answers(); } waitpid( $pid, 0 ); sub write_answers { foreach my $writehandle ( $sel->can_write ) { print "write handle is $writehandle\n"; return if $writehandle != $wtr; my $answer = shift @answers; print "writing $answer\n"; print $writehandle $answer . "\n"; } } #### rasto@frodo:~/work$ ./client.pl IN: GLOB(0x880fe78) OUT: GLOB(0x880fe88) ERR: GLOB(0x880fe28) PID was 6834 readhandle is GLOB(0x880fe78) readhandle is GLOB(0x880fe88) past next write handle is GLOB(0x880fe78) writing galahad rasto@frodo:~/work$