CTRL-Z on Win32

B

Bill Smith

My apology in advance to any who may consider this a Win32 question
rather than a perl question.

I recently bought the O'REILLY book "Learning Perl on Win32 Systems".
The introduction indicates that some modules that work under NT will not
work under other version of windows. There is no indication that basic
I/O might be different.

My problem is that none of the solutions to Chapter 3 Exercise 1 work on
my system (AS Perl v5.6.1 under Windows ME).

EXERCISE
1. Write a program that reads a list of strings on separate lines and
prints out the list in reverse order. If you're reading the list from
the console, you'll probably need to delimit the end of the list by
pressing CTRL-Z.
ANSWER
print "Enter the list of strings:\n";
print reverse <STDIN>";

The result using console input is correct except that the last line of
input is not printed.

I have searched the AS documentation and perldoc -q for "CTRL-Z" and for
"end-of-file" without success. Would someone here please explain the
problem and suggest a perl solution.

TIA,
Bill
 
R

Rhesa Rozendaal

Bill said:
I recently bought the O'REILLY book "Learning Perl on Win32 Systems".
The introduction indicates that some modules that work under NT will
not work under other version of windows. There is no indication that
basic I/O might be different.

There might be though, since the shells of Win95/98/ME are different
from those of WinNT/2000/XP.
EXERCISE
1. Write a program that reads a list of strings on separate lines and
prints out the list in reverse order. If you're reading the list from
the console, you'll probably need to delimit the end of the list by
pressing CTRL-Z.

I may be mistaken, but I'm pretty sure the text in that excercise is
wrong. ctrl-z on unix typically suspends the current process. You'd use
ctrl-d on unix to signal end of output.

"perldoc -q eof" gives me this question:

Why can't my script read from STDIN after I gave it EOF (^D on Unix,
^Z on MS-DOS)?
ANSWER
print "Enter the list of strings:\n";
print reverse <STDIN>";

What's that " doing there? You must have made a typo.
The result using console input is correct except that the last line of
input is not printed.

Did you enter the ctrl-z on a new line?

It works for me on windows 2000 and up, so you may indeed have run into
an IO difference between 98 and NT here. There's not much perl can do
for you. Just make sure you type in an extra blank line before doing ctrl-z.

Rhesa
 
A

A. Sinan Unur

use strict;
use warnings;
print "Enter the list of strings:\n";
print reverse <STDIN>";

D:\Home> perl st.pl
String found where operator expected at st.pl line 5, at end of line
(Missing semicolon on previous line?)
Can't find string terminator '"' anywhere before EOF at st.pl line 5.
The result using console input is correct except that the last line of
input is not printed.

It seems like, with command.com (0Win 98 SE), the following "works":

D:\Home> cat st.pl
use strict;
use warnings;

print "Enter the list of strings:\n";
print "\n", reverse <STDIN>;


D:\Home> perl st.pl
Enter the list of strings:
1
2
3
3
2
1

You will notice that the newline is not printed.

I am sure it's got something to do with some bug somewherein command com
but who knows.

Sinan.
 
B

Bill Smith

A. Sinan Unur said:
use strict;
use warnings;


D:\Home> perl st.pl
String found where operator expected at st.pl line 5, at end of line
(Missing semicolon on previous line?)
Can't find string terminator '"' anywhere before EOF at st.pl line 5.

Sorry about the extra quote mark. I intended to emphasize the direct
quote. After I realized the confusion, I failed to fix it correctly.
It seems like, with command.com (0Win 98 SE), the following "works":

D:\Home> cat st.pl
use strict;
use warnings;

print "Enter the list of strings:\n";
print "\n", reverse <STDIN>;


D:\Home> perl st.pl
Enter the list of strings:
1
2
3
3
2
1

You will notice that the newline is not printed.

I am sure it's got something to do with some bug somewherein command com
but who knows.

I had already discovered a similar work-around, but not coded it so
conceisly. It seems that the first line of output, after the CTRL-Z in
STDIN, is lost. This may be the best solution.
 
B

Bill Smith

Bob Walton said:
Try entering control-Z as the first character of a line. Windoze (at
least some versions) considers the control-Z to be a data character if
control-Z isn't the first thing typed on a line -- and note that you'll
also need to press the Enter key after typing the control-Z. And it is
a Windoze issue, not a Perl issue, as the same thing will happen with
programs in other languages.

You certainly clarified a secondary issue. The symptom that I described
can only happen if the CTRL-Z is the first character of the first line
after the last string.
 
B

Bill Smith

----- Original Message -----
From: "Rhesa Rozendaal" <perl&[email protected]>
Newsgroups: comp.lang.perl.misc
Sent: Saturday, November 20, 2004 9:15 PM
Subject: Re: CTRL-Z on Win32

There might be though, since the shells of Win95/98/ME are different
from those of WinNT/2000/XP.

I suspected that.
I may be mistaken, but I'm pretty sure the text in that excercise is
wrong. ctrl-z on unix typically suspends the current process. You'd use
ctrl-d on unix to signal end of output.

"perldoc -q eof" gives me this question:

Why can't my script read from STDIN after I gave it EOF (^D on Unix,
^Z on MS-DOS)?


This does not answer the question, but it does confirm that CTRL-Z is
the
correct charcater for eof.
What's that " doing there? You must have made a typo.

Right! I originally used quotes to indicate quotes from the book. When
I
realized the confusion that caused, I tried to remove them.
Did you enter the ctrl-z on a new line?

Tried it both ways. It is ignored if it is not at the start of a line.
It works for me on windows 2000 and up, so you may indeed have run
into

Thanks for trying it on other systems. I expected it to work, but hoped
that it would not.
an IO difference between 98 and NT here. There's not much perl can do
for you. Just make sure you type in an extra blank line before doing
ctrl-z.

This solution does not work in general. If I remove the call to
reverse, it
is the first string that is not printed. If a blank lines is supplied
at
the end, it is printed.
 
P

Paul Lalli

daniel kaplan said:
wow, must be my worst typo ever.....
*cents

also...and again new to perl so not sure how this affects, but CTRL-Z at the
end of the line as opposed to on a new blank line produces two different
results if you were cerating a file directly to DOS from the console...so
maybe that's it? again, too new to perl to say ... and i forget what ctrl-z
does....indicate EOF? i really forget, it some carry over from CP/M if i
recall.....not sure what CTRL-D does

Once again, this problem is wholly unrelated to the language being used.
EOF is EOF, regardless of the language used to read from standard input.
The constant disclaimer you offer of "too new to perl" is irrelevant.
The keystroke used to symbolize EOF is defined by the operating system
(or shell?), not by the language that happens to have created the
program.

Paul Lalli
 
A

Arndt Jonasson

daniel kaplan said:
...again, i was just postulating (sp?) on what ctrl-z does (as it's too old,
or i am also)

I think "speculating" is the word you want.
 
P

Paul Lalli

daniel kaplan said:
...if you re-read what i said it was, i don't know how it affects Perl in
that, depending where the ctrl-z is placed, you might get one extra line...i
was not claiming how ctrl-z affected perl, but how the extra blank line (or
lack thereof) affect the code he was writing....

Please do not accuse me of not reading your post before replying. Thank
you.

I *know* you don't know how "it affects Perl". That's why I'm telling
you that it does not. That is the point of making such replies - to
inform and educate someone who clearly does not have a certain piece of
knowledge. The secondary point of my post was to attempt to explain to
you why your almost-constant disclaimers of "I don't know Perl well,
but..." are irrelevant to the problem at hand. This is part 2 in my
attempt this week at helping you to correctly partition a problem (the
first being the CGI/Perl thread). If you do not want assistance in this
area, allow me to suggest you make an effort to learn the skill on your
own.

Thank you,
Paul Lalli
 
P

Paul Lalli

daniel kaplan said:
i feel i have to say this with EVERY post i have made when I try to help
someone....this thread was my second or third....i feel i have to say that
because we've all been there where we can't figure out "what on earth is
happening" and we just reach out to any straws we can clutch at.....but i
feel even in those situations, that not explainning i am a newbie would be
misleading....hence, "take this with a grain of salt since it's comign from
me"

hope that better explains it?

You continue to miss my point entirely. I'm not claiming it's wrong of
you to prepend attempts at helping with Perl problems with a "I'm new at
this" warning. I'm trying to get you to understand that your "Perl
newbie" warning in this thread is as useful and meaningful as the
statement "I'm new at changing my car's tires, but . . . " would have
been in its place.

I'm just trying to help you understand that the first part in solving a
problem is to understand what the problem is. Throwing in random
statements that have nothing to do with a problem are red herrings that
can serve only to add to the confusion of both the original questioner
as well as any future readers of the thread. Therefore, it is most
beneficial to everyone involved to try to determine what the problem is
(or at the very least, what it is *not*) before posting.

With that, I'm done with this thread. I hope I was able to help a
little.

Paul Lalli
 
B

Bill Smith

daniel kaplan said:
bill,

this is already a few days old, so between rhesa and yourself you probably
already figured it out.
is it having to do the ctrl-z on a separate line? possibly. i am still a


I have been having a problem with my newsgroup server and been unable to
reply for a few days.

Thanks for all who replied, especially those who tested on other
systems. I have concluded that there are several minor differences in
the way that MS systems handle CTRL-Z. Perl cannot fix this problem.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,271
Latest member
BuyAtenaLabsCBD

Latest Threads

Top