[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:01770] $stdin and DATA

From: Dave Thomas <Dave@...>
Date: 2000-03-07 03:43:28 UTC
List: ruby-talk #1770
Was was trying to test a program that would normally read using
Kernel#gets. Because I wanted the test to be self contained, I thought 
I'd include the test data in the file:

   while DATA.gets
     # ...
   end
   __END__
   stuff...

This worked fine. However, to make the changeover between test and
production easier, I thought I'd be clever:

   $stdin = DATA
   while gets
     # ...
   end
   __END__
   stuff...

But this doesn't seem to work. Then, while playing with this, I
discovered something equally strange:

   $stdin = DATA
   while DATA.gets
     # ...
   end
   __END__
   stuff...

Simply assigning DATA to $stdin stops the loop from working.


Is there a way to do what I need - to have a plain 'gets' read from
DATA? And is the above behavior expected?

Regards


Dave

In This Thread

Prev Next