Problem with process

M

Markus Blasl

Hi,

can anyone give a hint, why ruby skips the input, when i run this
following code?

thanks,
Markus

#!/usr/bin/ruby
def search()
puts "Suchbegriff: ";
search=gets;
chop
search = $_
search = "Welt";
ARGV.each do |test|
File.open("#{test}", "r") do |afile|
if (afile.gets =~ /#{search}/i)
puts test.to_s
end
end
end
end
search()
 
T

ts

M> #!/usr/bin/ruby
M> def search()
M> puts "Suchbegriff: ";
M> search=gets;

search = $stdin.gets # otherwise ruby read a line from the
# first file given in argument, and this file
# is removed from ARGV

M> chop



Guy Decoux
 
R

Robert Klemme

Paul Brannan said:
This confused me the first time I saw it, and now I always use
$stdin.gets() instead of just gets(). Is there anyone out there who
actually uses this feature of Kernel#gets()?

Yep.

robert
 

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

Forum statistics

Threads
474,104
Messages
2,570,643
Members
47,246
Latest member
rangas

Latest Threads

Top