[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

gets under Windows & Unix

William James

5/16/2006 8:27:00 AM

ruby -ne 'print; gets if ARGF.eof' file*

The object is to print line 1 from file 1 and lines 2 through last
from every file.

A perl user alleged that under Unix:

> That will print out the file contents and then wait for more input from stdin
> so you have to follow it with ^D to signal EOF.

Not having access to a Unix or Linux system, I would be grateful
if someone would test this.

6 Answers

ts

5/16/2006 9:33:00 AM

0

>>>>> "W" == William James <w_a_x_man@yahoo.com> writes:

W> A perl user alleged that under Unix:

>> That will print out the file contents and then wait for more input from stdin
>> so you have to follow it with ^D to signal EOF.

no, no : it don't wait for more input from stdin.

it read from stdin *only* if you don't give argument to the command.

--

Guy Decoux

Jeff Schwab

5/16/2006 10:11:00 AM

0

ts wrote:
>>>>>> "W" == William James <w_a_x_man@yahoo.com> writes:
>
> W> A perl user alleged that under Unix:
>
>>> That will print out the file contents and then wait for more input from stdin
>>> so you have to follow it with ^D to signal EOF.
>
> no, no : it don't wait for more input from stdin.
>
> it read from stdin *only* if you don't give argument to the command.

Yep. It's also buggy: when multiple files are given, the gets() will
read the first line of each file after the first, i.e. it will try to
read one line from *ARGF /after/ the end of each individual ARGF file.

To get the intended behavior, you may want something like this:

ruby -pe '' file* -

Btw, please don't hold this against all Perl users. Despite the amount
of libel Perl suffers in Ruby and Python groups, it is actually a
wonderful language.

William James

5/16/2006 5:24:00 PM

0

ts wrote:
> >>>>> "W" == William James <w_a_x_man@yahoo.com> writes:
>
> W> A perl user alleged that under Unix:
>
> >> That will print out the file contents and then wait for more input from stdin
> >> so you have to follow it with ^D to signal EOF.
>
> no, no : it don't wait for more input from stdin.
>
> it read from stdin *only* if you don't give argument to the command.


Yes, this is the way it works on my windows 2000 computer.
However, I just tested it on a windows xp computer. After printing
the files, it attempts to read from stdin and I have to press ^Z !

The code in question is
ruby -ne 'print; gets if ARGF.eof' file*

My Ruby version on the xp box is ruby 1.8.2 (2004-05-19)
[i386-mswin32].

Is this a bug in my version of Ruby?


>
> --
>
> Guy Decoux

ts

5/17/2006 8:36:00 AM

0

>>>>> "W" == William James <w_a_x_man@yahoo.com> writes:

W> Is this a bug in my version of Ruby?

Probably or in windows.


--

Guy Decoux

William James

5/17/2006 5:22:00 PM

0

William James wrote:
> ts wrote:
> > >>>>> "W" == William James <w_a_x_man@yahoo.com> writes:
> >
> > W> A perl user alleged that under Unix:
> >
> > >> That will print out the file contents and then wait for more input from stdin
> > >> so you have to follow it with ^D to signal EOF.
> >
> > no, no : it don't wait for more input from stdin.
> >
> > it read from stdin *only* if you don't give argument to the command.
>
>
> Yes, this is the way it works on my windows 2000 computer.
> However, I just tested it on a windows xp computer. After printing
> the files, it attempts to read from stdin and I have to press ^Z !
>
> The code in question is
> ruby -ne 'print; gets if ARGF.eof' file*
>
> My Ruby version on the xp box is ruby 1.8.2 (2004-05-19)
> [i386-mswin32].
>
> Is this a bug in my version of Ruby?


Guy Decoux wrote

> W> Is this a bug in my version of Ruby?

> Probably or in windows.


And apparently this same bug exists in a version of Ruby
running under Unix or Linux, because the Perl-user said
he had to press ^D.

It is pitiful that Ruby can't even execute "gets" properly.

ts

5/18/2006 8:18:00 AM

0

>>>>> "W" == William James <w_a_x_man@yahoo.com> writes:

W> It is pitiful that Ruby can't even execute "gets" properly.

ruby just work fine, this is the P language which is buggy :-)


--

Guy Decoux