Re: Can perl find strings over multiple lines?

Discussion in 'Perl' started by Vronans, Nov 20, 2006.

  1. Vronans

    Vronans Guest

    Paul Lalli wrote:
    > wrote:
    >> Is it possible to search for strings in a file over multiple lines
    >> using a one-liner from the shell?

    >
    > Yes, it is.
    >
    >> What I want to do is find all the text between
    >> a line beginning with "--" or "-- " and
    >> ending with ")$" where '$' is, of course, the EOL char.
    >>
    >> I also would like to know how to find the exclusion
    >> so that the output produces everything but the enclosed string above.
    >> Is this possible with perl?

    >
    > Yes, it is.
    >
    > If you would like assistance with the demonstration of such abilities,
    > please read and follow the Posting Guidelines for the group. Most
    > specifically, please post your best attempt to solve the problem
    > you're having, along with a description of how your attempt is not
    > working sufficiently. Be sure to include example input, desired
    > output, and actual output.


    While it's always good for one to attempt to solve their own problem, I
    don't see why the assumption is often made that they did not do so.
    Further more, why are some people so concerned with that in the first
    place? Especially for a potentially simple answer in this case.

    He gave a description of what he was trying to do. You could of included
    an answer similar like mine )below) instead of just general guidelines
    and leave it at that. Do not get me wrong, your guidelines are good for
    general purposes, but by themselves do not really offer anything to the
    topic it self.



    It sounds to me like he could find the 's' modifier for a regex match,
    which cause the '.' meta char to match embedded new lines.

    This should to do what the OP wants (un tested):

    @matches = $full_text =~ m!--(.*?)\)\$!sg;
     
    Vronans, Nov 20, 2006
    #1
    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. Rigga

    Text over multiple lines

    Rigga, Jun 20, 2004, in forum: Python
    Replies:
    10
    Views:
    700
    Rigga
    Jun 21, 2004
  2. Sara
    Replies:
    6
    Views:
    275
    John W. Krahn
    Apr 12, 2004
  3. Markus Dehmann
    Replies:
    1
    Views:
    141
    Tad McClellan
    Sep 26, 2006
  4. Replies:
    5
    Views:
    299
    DJ Stunks
    Nov 20, 2006
  5. Cah Sableng
    Replies:
    0
    Views:
    247
    Cah Sableng
    Apr 23, 2007
Loading...

Share This Page