Can perl find strings over multiple lines?

O

osiris

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

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? Thanks a million.

I have perl 5.8.6 on OSX 10.4 and 5.6.1 on Solaris 7.
 
C

cyborg

Give us some examples instead of just descriptions.
Some sample text, maybe, or the original plus the result you want to
achieve.
 
P

Paul Lalli

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.
Thanks a million.

You're welcome.

Paul Lalli
 
V

Vronans

Paul said:
Yes, it is.


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;
 
P

Paul Lalli

[removed non-existent group 'comp.lang.perl']
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.

Because absolutely no indication of any kind was given that the OP made
any attempt.
Further more, why are some people so concerned with that in the first
place?

Because this newsgroup is not a free tech-support system. Everyone who
answers a post here is a volunteer. There are only so many posts that
any one person can volunteer to answer in a given day. Most people
here, myself included, are for more inclined to offer assistance to
people who've demonstrated an attempt to solve the problem first.
Therefore, someone who makes no such demonstration is far less likely
to have their problem answered.

My comments were intended to help the OP help himself. By making an
attempt and following the Guidelines of the group, the OP has the best
chance to actually get his problem solved.

If you want to go ahead and solve people's problems regardless of the
content of their questions, by all means, please continue to do so. No
one will stop you, and I for one will applaud you. ... Right up to the
moment where you say "enough is enough" and decide you can't devote any
more time to doing so.
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.

Nor are they supposed to. I am of the "Teach a Man to Fish"
philosophy. Your response helps the OP with this one particular post.
Will you necessarily be here to also answer his next one? And the one
after that? My response teaches him how to ask a better question so
that next time, far more people will be likely to respond to him, in
case you're not around.

Paul Lalli
 
D

DJ Stunks

Vronans said:
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;

Aside from the points Paul made in rebuttal with which I agree
strongly, I think it's worth mentioning that your solution is by your
admission untested, and "should" do what the OP wants provided you've
interpreted his description correctly.

Anything I post I test, something made impossible by not having sample
input and desired output.

Secondly, we have, many times in the past, provided solutions to
posters only to find out later on that their description was poor, and
frequently misses edge cases. I would rather give a definitive answer
once than multiple guesses at potential solutions.

Finally, the posting guidelines are to help the posters, not the
responders. Programming is, and must always be, an exact science. If
an individual cannot express their issue exactly and specifically I
don't think they're going to have much luck in their programming
career. Getting them to formulate such a question should help them
think logically and rationally, but if not, I'm sure "ballet reviewer"
is still available as a career choice.

-jp
 

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
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top