Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Extracting range of lines
tmarc
7/15/2008 11:06:00 AM
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/ch...
I've been googling around with no relevant results.
Thanks in advance,
Tom
2 Answers
smn
7/15/2008 11:43:00 AM
0
the link is not working (i would need to sign up to the forum
first...)
On Jul 15, 1:05 pm, tmarc <tmarcin...@gmail.com> wrote:
> 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/ch...
>
> I've been googling around with no relevant results.
>
> Thanks in advance,
> Tom
Peña, Botp
7/15/2008 11:55:00 AM
0
From: tmarc [mailto:tmarciniak@gmail.com]=20
# 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/ch...
# 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=3Df.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"
#=3D> nil
File.open("test.txt") do |f|
while line=3Df.gets
p line if line =3D~ /^--second/ .. /^--third/
end
end
"--second\n"
#=3D> nil
so you get weird results.
the new ruby syntax is like,
File.open("test.txt") do |f|
while line=3Df.gets
p line if line =3D~ /^--second/ .. line =3D~ /^--third/
end
end
"--second\n"
"546\n"
"3456\n"
"5436\n"
"9879\n"
"--third\n"
#=3D> nil
hth.
kind regards -botp
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Extracting range of lines
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password