> -----Original Message-----
> From: Steven M. Klass [mailto:[EMAIL PROTECTED]]
> Subject: Multiline searching - 
> 
> 
> Hi all,
> 
>       I have a text that broken into sections.  Each section 
> has comments(;) and 
> can be placed anywhere,  Each section ends with "*ENDS" .  
> Each section 
> begins with a *KEYWORD, where keyword is any word like DESCRIPTION, 
> OPERATION, FOO, AND BAR.  I want to read in this one section 
> at a time.  I 
> then want to work exclusively on one section(DESCRIPTION).  
> Can someone 
> enlighten me a bit.  I want to know how to read this in by 
> section (as oposed 
> to line) that ends with (*ENDS).  Then I want to know how to 
> tell what 
> section I'm in (*DESCRIPTION), and then I want to know where 
> to do my search 
> and replace (s/INFILE/TEST/).  I hope someone can help me 
> out.  Thanks so 
> much for your continued patience!
> 
> Example Text
> <snip>
> ; Test 
> ; Test
> *DESCRIPTION
> ; More comments
> INFILE = blach
> OUTFILE = test
> ;
> 
> ;
> *ENDS
> ;
> ;
> *LAYERS
> LAYER=1
> ;
> *ENDS
> ;
> <snip>

I'm assuming this text is in a file... Here is some code to read in the
records and find the sections and keyword for each section (assuming that
each section only has one keyword, and that it starts with '*').

use warnings;
use strict;

$/ = "*ENDS\n"; #change the record separator
open (FILE, "test1.txt") || die "Can't open test1.";
while (defined(my $Section = <FILE>)) {
  my ($KeyWord) = $Section =~ /\*(.*)\n/;
  print "Information for $KeyWord section:\n" if ($KeyWord);
  print "$Section\n\n";
}

I'm not sure what you mean when you say "and then I want to know where to do
my search and replace (s/INFILE/TEST/)."
If you just want to replace INFILE with TEST in this section, you would
simply use the regex you have, binding it to (in this case) $Section.
  $Section =~ s/INFILE/TEST/;

On the other hand, if you want to know what lines are not comments, and each
non-comment line contains "TEXT = info" you could look for the '='.
  my (@TextToReplace) = $Section =~ /(.*)\s*=/g;

This regex could be modified if you wanted to store both the TEXT and the
info, giving a final code of something like this...

use warnings;
use strict;

$/ = "*ENDS\n";
open (FILE, "test1.txt") || die "Can't open test1.";
while (defined(my $Section = <FILE>)) {
  my ($KeyWord) = $Section =~ /\*(.*)\n/;
  print "Information for $KeyWord section:\n" if ($KeyWord);
  my (@TextToReplace) = $Section =~ /(.*)\s*=\s*(.*)/g;
  my %RTHash;
  my $x=0;
  while ($x<=@TextToReplace) {
    $RTHash{$TextToReplace[$x]} = $TextToReplace[$x+1] if
($TextToReplace[$x]);
    $x+=2;
  }
  foreach my $key (keys %RTHash) {
    print "replacement text is: $key, which has a value of: $RTHash{$key}\n"
if ($key);
  }
  print "$Section\n\n";
}

You may want to break up parts of this into subroutines, but this should get
you started.

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:

************************************************************************

The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.

************************************************************************

Reply via email to