Thanks Bob, I'm going to file this away in
my nifty perl code file.

-----Original Message-----
From: Bob Showalter [mailto:[EMAIL PROTECTED]
Sent: Monday, September 08, 2003 10:29 AM
To: Akens, Anthony; [EMAIL PROTECTED]
Subject: RE: Matching a section of test


Akens, Anthony wrote:
> Sorry for the first post, didn't mean this as
> a reply.
> 
> 
> Hello all...
> 
> I'm wanting to write a script that scans a file,
> ignoring all lines until it reaches a certain
> section, then processes all lines in that
> section that are not comments, until it reaches
> the end of that section.
> 
> The section would be designated like this:
> 
> ## Beging Processing ##
> 
> ## End Processing ##
> 
> So I open my file, and skip all lines until I
> see that first bit...  Then do stuff until I
> see the last bit.  Can someone help me out with
> this?
> 
> Tony
> 
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> open (FILE, "<myfile")
>         or die "Could not open Template. ($!)";
> 
> while ($line = <FILE>) {
>       #skip until beginning....
> 
>       #End when "End Processing" is reached
>       last if $line =~ "End Processing";
> 
>       #Process the lines in between
>       next if $line =~ /^#/;
>       #do stuff....
> }

The range operator in scalar context can handle this kind of thing. See
perldoc perlop and search for "Range Operators".

   while (<FILE>) {
      if (/^## Begin/ .. /^## End/) {
         ...do stuff here with $_
      }
   }

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to