Craig Cardimon wrote:
> I have something like this:
>
> while (<FILE>)
> {
>    if (/<TAG>/ .. /<\/TAG>/)
>    {
>        # process line
>    }
> }
>
> I got this from http://www.perl.com/pub/a/2004/06/18/variables.html.
>
> My special wrinkle is, I want to process certain sections of a file, but 
> only if that section passes certain criteria.
>
> I want to be able to begin processing lines, but I want to be able to 
> turn processing off and jump to the next <TAG> should the script 
> encounter a line containing, say, the tag <PDF>.
>   
Something like this should work:
#!/usr/bin/perl -w

use strict;

my $KeepGoing = 1;

while (<FILE>)
{
   $KeepGoing = 1 if /<TAG>/; # reset on the next <TAG>

   if ((/<TAG>/ .. /<\/TAG>/) && $KeepGoing)
   {
       if (/<PDF>/)
       {
             $KeepGoing=0;  # stop processing until the next <TAG>
             next;
       }

       # process line
      
   }

}


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to