Extracting range of lines

Hello,

are there a ruby equivalents to perl’s /regex/ … /regex/ and /
regex/ … /regex/ idioms, examples described at
http://www.unix.com.ua/orelly/perl/cookbook/ch06_09.htm?

I’ve been googling around with no relevant results.

Thanks in advance,
Tom

the link is not working (i would need to sign up to the forum
first…)

From: tmarc [mailto:[email protected]]

are there a ruby equivalents to perl’s /regex/ … /regex/ and /

regex/ … /regex/ idioms, examples described at

Recipe 6.8. Extracting a Range of Lines?

I’ve been googling around with no relevant results.

try searching for ruby+range+flip+flop

iianm, that perl/sed style is being deprecated.

eg,

File.open(“test.txt”) do |f|
while line=f.gets
p line
end
end
“–first\n”
“1234\n”
“456\n”
“4321\n”
“654\n”
“–second\n”
“546\n”
“3456\n”
“5436\n”
“9879\n”
“–third\n”
“1111\n”
#=> nil

File.open(“test.txt”) do |f|
while line=f.gets
p line if line =~ /^–second/ … /^–third/
end
end
“–second\n”
#=> nil

so you get weird results.

the new ruby syntax is like,

File.open(“test.txt”) do |f|
while line=f.gets
p line if line =~ /^–second/ … line =~ /^–third/
end
end
“–second\n”
“546\n”
“3456\n”
“5436\n”
“9879\n”
“–third\n”
#=> nil

hth.
kind regards -botp