sub read_sock { my( $rout, $wout, $win, $eout, $ein, $found, $line, $timeleft, $read_status, @out ); #my $sock_read = $$sock_global; my $buf=''; my $prompt = $_[0]; my $prompt_check = $_[1] || 1; my $prompt_match=0; my $timeout = 0; my $rin = ''; # Initialise to an empty set # (NOTE: $rin=0 is very wrong) vec($rin, fileno($sock), 1) = 1; # Set the appropriate bit while($prompt_match < $prompt_check) { ($found,$timeleft) = select($rout=$rin,$wout=$win,$eout=$ein,$timeout); if ($found == 1) { $read_status=0; #print "FOUND:"."$found\n"; $read_status = sysread($sock,$line,1024); if($read_status) { $buf = "$buf"."$line"; } if($line =~ /$prompt/) { #print "match found\n"; $prompt_match++; } } } @out = split(/\r/,$buf); return(\@out); }