in reply to windows keyboard input

If the reply on ^Z wasn't what you had in mind, then maybe you should clarify.

If a program is running and reading from stdin, then pressing ^Z on Win32 (or ^D on Unix) will make the program see EOF on that file handle.

So if you wrote:

@a= <>;
then typed a bunch of stuff, ^Z would terminate the array-read and let the program go on. E.g.
@a= <>; foreach (@a) { $total += $_; ++$count; } print "total of $count items is $total\n";
Running it,
1 2 5 6 ^Z total of 4 items is 14

Replies are listed 'Best First'.
Re: Re: windows keyboard input
by binary* (Novice) on Oct 06, 2001 at 02:32 UTC
    That was very helpful! I had STDIN inside the diamond operator which works fine on linux, but doesn't on windows. Eliminating STDIN inside the diamond brackets allows CTRL-Z to work as expected. In linux, the keyboard interruption works with CTRL-D for both the empty diamond operator on the diamond operator with STDIN inside. Thanks
      I'm glad to help.

      diamond or STDIN work the same in my example. Are you wanting more than one array read in the same program? There I can see a difference, since diamond will try the "next file" and I suppose reopens stdin.

      —John

        I spoke too soon. When I copy and paste your example onto my win98 machine, run it, key in letters, and press CTRL-Z I get error messages complaining about arguments "asdf\n" not being numeric in addition (which I would expect), but your code still added up the number of items entered indicating that control had returned to the program. I jumped to the conclusion that this would work properly if numbers were entered (like your example). When I went back and tried it with numbers for input, the program just ended with no output when I held down the Ctrl Key and pressed z. I wasn't trying to read multiple files or arrays, only take multiple lines of input from the command line. If your example works on your windows machine, something else must be going on besides the perl code. Thanks