Extracting range of lines

Discussion in 'Ruby' started by tmarc, Jul 15, 2008.

  1. tmarc

    tmarc Guest

    tmarc, Jul 15, 2008
    #1
    1. Advertising

  2. tmarc

    smn Guest

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

    On Jul 15, 1:05 pm, tmarc <> wrote:
    > Hello,
    >
    > are there a ruby equivalents to perl's /regex/ .. /regex/ and /
    > regex/ ... /regex/ idioms, examples described athttp://www.unix.com.ua/orelly/perl/cookbook/ch06_09.htm?
    >
    > I've been googling around with no relevant results.
    >
    > Thanks in advance,
    > Tom
     
    smn, Jul 15, 2008
    #2
    1. Advertising

  3. tmarc

    Peña, Botp Guest

    From: tmarc [mailto:]=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/ch06_09.htm?
    # 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
     
    Peña, Botp, Jul 15, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. test
    Replies:
    0
    Views:
    2,358
  2. Ron Coutts
    Replies:
    0
    Views:
    117
    Ron Coutts
    Dec 15, 2003
  3. Kris Leech

    extracting lines from an address

    Kris Leech, Nov 17, 2005, in forum: Ruby
    Replies:
    8
    Views:
    177
    William James
    Nov 17, 2005
  4. it_says_BALLS_on_your forehead

    extract range of lines using range op bug?

    it_says_BALLS_on_your forehead, Mar 3, 2006, in forum: Perl Misc
    Replies:
    3
    Views:
    208
    it_says_BALLS_on_your forehead
    Mar 3, 2006
  5. vivek_12315

    Extracting a range of words!

    vivek_12315, Dec 16, 2010, in forum: Perl Misc
    Replies:
    5
    Views:
    155
    Justin C
    Dec 17, 2010
Loading...

Share This Page