I seem to be experiencing inconsistency when I invoke;

 

$user_input = <STDIN>;

 

in some programs the behavior is as expected.  at that point in the program
I type in some input from keyboard then the moment I press the 'enter' key,
the program flow returns back to the executing Perl program.

 

other times, I get a rather unusual response.  

 

I type in user input from the keyboard and when I press the 'enter' key,
instead of having program flow return back to the program, the enter key is
instead OUTPUT TO THE DOS CONSOLE SCREEN and the cursor drops down one line
on the console screen!  when this happens, the program flow does NOT return
back to the program and my program just hangs there.

 

any explanation for this?

 

more importantly, whats the fix?

 

 

 

 

today it just happened again.  the relevant block of code is here.

 

sub main_loop {

 

        while (1) {

 

                system("cls");

 

                print "Test tcp/ip client/server request/response from
server x using port 80\n\n

Press:

 

   'H' to test HTTP request/reponse

   'X' to test XML  request/reponse

   'Q' to Quit

 

Test which application protocol:\n";

 

                my $ui = <STDIN>;

 

                if      ($ui =~ /x/i) {

                        my $request = &assign_xml_request_from_xml_file;

                        &attempt_request_response($request);

                } elsif ($ui =~ /h/i) {

                        my $request = &assign_http_request_from_http_file;

                        &attempt_request_response($request);

                } elsif ($ui =~ /q/i){

                        print "\nProgram Terminated\n";

                        close $main::socket;

                        exit;

                } else {

                        next;           #loop

                }

 

        }

 

}

 

 

the full program is here:

 

 

use IO::Socket;

use Strict;

use Warnings;

 

our $socket;

 

&open_tcp_socket;

&main_loop;

 

 

 

### sub routines ###########################################################

 

sub open_tcp_socket {

 

            $main::socket = new IO::Socket::INET ( Proto      => "tcp",

                                                PeerAddr =>
"siteundertest.com",

                                                PeerPort => "80",

                               ) or die "Error: Cannot create tcp/ip socket
($!)\n";

            $main::socket->autoflush(1);

}

 

 

sub main_loop {

            not duplicated in email - this is found above

}

 

 

sub assign_xml_request_from_xml_file {

            open (IN, "xml.request");

            undef $/;

            my $xml_request = <IN>;

            return $xml_request;

}

 

 

sub assign_http_request_from_http_file {

            open (IN, "http.request");

            undef $/;

            my $http_request = <IN>;

            return $http_request;

}

 

 

sub attempt_request_response {

            my $response;

            $main::socket->send($_[0]);

            $main::socket->recv($response, 8192);

            system("cls");

            print "Response =\n\n$response";

            sleep(10);

}

 

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to