From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Greg Aiken Sent: 16 April 2009 16:25 To: perl-win32-users@listserv.activestate.com Subject: active perl 5.8.8 build 820 inconsistent behavior with $input =<STDIN>;
> 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... Actually, I think the relevant block of code may be further down. [Some stuff deleted] > sub assign_xml_request_from_xml_file { > open (IN, "xml.request"); > undef $/; You have just globally changed the input record separator to slurp mode, for all input. This may be the cause of your problem. This is one of the few instances where 'local' is needed, i.e. to temporarily change the value of a special variable. Make that: local $/; > 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; > } The above two functions look identical apart from the filename, so why not use a single function. For example, here is one I wrote earlier: sub read_file { my $fn = shift; open my $fd, "<", $fn or die "Failed to open $fn: $!\n"; local $/; my $data = <$fd>; close $fd; return $data; } Note the 3 argument form of open, and the localised file handle. Or course, if you can install File::Slurp, you don't even need to write one. Also, its better to call subs without the '&' prefix, unless you know what that does, and you need it. HTH -- Brian Raven This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs