Hi
The simplest approuch would be to something like this:
# @files contains the files to be processed.
for my $file (@files){
my $content;
local $/ = ''; # Sets the INPUT_RECORD_SEPERATOR as empty string
open(IN, $file)
or warn "Couldn't open $file for reading: $!";
$content = <IN>;
close(IN);
# Take everything that's between EXP1 and EXP2 if they exist
if ($content =~ /EXP1(.+)EXP2/s){
print $1; # Contains what's between the parenthesis
}
}
Best regards,
Grétar
Rimma Nayshulis wrote:
Hi,
I've never used perl before, but was told that it's pretty powerful for text
processing.
Here's a problem I'm trying to solve:
I have an expression, exp1 that I need to grep for recursively over a
directory structure. If I find a match, I need to look at the matching file
and find another expression, exp2. Both exp1 and exp2 belong to the same
pattern that always looks like this
{
exp2 "some text"
some lines of text
some lines of tex
.....
exp1
more lines of text
more lines of text
....
}
The goal of this exercise is to see what "some text" says in the files that contain exp1.
I can always read all of the files recursively line by line, save each line into an array until I find exp1 and then go backwards through the array until I find exp2 and see what "some text" on that line is, but I was wondering if I can somehow use regular expressions over multiple lines to do this.
I hope this is a clear explanation of my problem.
Any insights or pointers to resourcesare greatly appreciated!
Thanks!
---------------------------------
Relax. Yahoo! Mail virus scanning helps detect nasty viruses!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>