Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / February 2006



Tip: Looking for answers? Try searching our database.

Control-D Bug?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jonathan Levi MD - 01 Feb 2006 04:43 GMT
Doing an early problem (reading, reversing and printing a list of
strings read from input) in the Llama Book, 4th Ed., I wrote:

   #!/usr/bin/env perl
   # [comments omitted]
   print reverse <>;

This worked with a separately created input file:

   drj2:learningperl4 jonathan$ cat someInput.txt
   1
   2

   3
   drj2:learningperl4 jonathan$ p052e1.pl someInput.txt
   3

   2
   1

but it didn't work quite that way when I used standard input,
terminated with control-D:

   drj2:learningperl4 jonathan$ p052e1.pl
   1
   2

   3
   3D

   2
   1

Is this supposed to happen?  --MacOS X 10.3.9, perl "v5.8.1-RC3 built
for darwin-thread-multi-2level (with 1 registered patch, see perl -V
for more detail)"

tia,

Jonathan
Paul McCann - 01 Feb 2006 05:43 GMT
Jonathan Levi wrote:

> #!/usr/bin/env perl
>    # [comments omitted]
>    print reverse <>;

> drj2:learningperl4 jonathan$ p052e1.pl
>    1
[quoted text clipped - 5 lines]
>    2
>    1

I'm pretty sure that you're just seeing an artefact of executing in  
the terminal (ie it's a display problem, rather than a problem with  
the output).

If you try to "catch" the output instead, via

p052e1.pl > output.txt

and then "less output.txt" you should notice that the "^D" terminated  
input gives the same result as when you point at a file for the input.

Cheers,
Paul
Jonathan Levi MD - 01 Feb 2006 18:01 GMT
>Jonathan Levi wrote:
>
[quoted text clipped - 19 lines]
>terminated input gives the same result as when you point at a file
>for the input.

You were right, the stray "D" didn't appear in output.txt, so I don't
have to worry about it creeping into output files. Many thanks,
Jonathan
Edward Moy - 01 Feb 2006 18:14 GMT
FYI, when you type CTRL-D, the tty driver echos back 4 characters ^D\b
\b (where \b is <CTRL-H> or backspace).  So when perl outputs its  
first line, it writes 3\n (which the tty driver converts to 3\r\n),  
so the ^ is overwritten by the 3, leaving 3D.

Edward Moy
Apple

>> Jonathan Levi wrote:
>>
[quoted text clipped - 23 lines]
> don't have to worry about it creeping into output files. Many  
> thanks, Jonathan
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.