End Record Charcter

B

Bruce.Dobson

I am trying to learn some Perl and doing a tutorial which has the following
code.
%grades = ();
print "Enter student names (press <cntrl>+D when done:";
@names = <STDIN>;
chomp @names;
print "\n\n";
print "Enter corresponding grades (press <cntrl>+D when done):";
@scores = <STDIN>;
@grades{@names} = @scores;

It refers to <cntrl>+D as the "end record character", but this does not seem
to work for me when I run the programme.
I installed ActivePerl-5.8.0.806-MSWin32-x86.msi on Windows XP.
Can anybody tell me why I cannot get <Cntrl>+D to work or what I use for the
end record character instead of <Cntrl>+D.
--
Bruce Dobson
8 Prescott Place,
Hamilton,
New Zealand.
Ph 064 7 856 8804 Fax 064 856 8845
Mobile 027 230 7509
 
B

Bob Walton

Bruce.Dobson said:
I am trying to learn some Perl and doing a tutorial which has the following
code.
%grades = ();
print "Enter student names (press <cntrl>+D when done:";
@names = <STDIN>;
chomp @names;
print "\n\n";
print "Enter corresponding grades (press <cntrl>+D when done):";
@scores = <STDIN>;
@grades{@names} = @scores;

It refers to <cntrl>+D as the "end record character", but this does not seem
to work for me when I run the programme.
I installed ActivePerl-5.8.0.806-MSWin32-x86.msi on Windows XP.
Can anybody tell me why I cannot get <Cntrl>+D to work or what I use for the
end record character instead of <Cntrl>+D.

Control-D has nothing to do with Perl per se, but is an operating system
feature. Generally control-D may be used to give an end-of-file
indication on console input to an application on a Unix system. On
Windoze, it is more or less a control-Z. Your mileage might vary
depending upon your version of Windoze -- some versions have a bug which
hides the next line of output from your program following a control-Z,
which can be most highly confusing. This is a Windoze bug, since other
programs besides Perl do it too. A workaround is to simply output an
extra blank line before printing anything else after a control-Z.
Better yet (paricularly in the case with data like you've got) would be
to key the data into a file using an editor, and then read that file
with Perl. That way one typo doesn't ruin a long series of data input,
and you get to run various versions of your program, or even other
programs, on the data without having to type it all in again.
 
B

Bruce.Dobson

Bob, thanks for your reply - <Cntrl>+Z works fine! Thank you also for your
advice regarding adding the info using a text editor file - I think that
process is coming up shortly in the exercises I am working on in the book
"Perl - Weekend Crash Course". I am learning Perl for a student assignment
that I am doing building an auction site.
It is mid spring here and the weather is slowly improving - I hope I can say
the same for my Perl programming!
It is really good to know that there is great help available at this
Newsgroup site.
Cheers
--
Bruce Dobson
8 Prescott Place,
Hamilton,
New Zealand.
Ph 064 7 856 8804 Fax 064 856 8845
Mobile 027 230 7509
 

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
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top