Sharan Basappa wrote:
> On Fri, Oct 10, 2008 at 9:49 PM, Rob Dixon <[EMAIL PROTECTED]> wrote:
>>
>> If your problem really is that simple, and you don't expect 'keywordy' 
>> blocks to
>> be nested inside other 'keywordy' blocks, then the program below will do what
>> you need.
>>
>> It may help if you showed us some actual data so that we could get a better
>> insight into how it behaves.
>>
>>
>> use strict;
>> use warnings;
>>
>> while (<DATA>) {
>>  print if /\bkeywordy\b/ .. /\bendkeywordy\b/;
>> }
>>
>> __DATA__
>> keywordx ...
>>
>>  keywordy identifier_a
>>    some text
>>  endkeywordy
>>
>>  keywordz identifier_a
>>    some text
>>  endkeywordz
>>
>> endkeywordx
>>
>
> Thanks, Rob. I will give a try with this code. But given that there
> are new lines between keyword and endkeyword,
> do you think it will work.

I am certain that it will work if the data is similar to what you have
described. I hope it is obvious that my program reads the input file line by
line, and you would need to write

  open my $fh, '<', 'filename' or die $!;

  while (<$fh>) {
    :
  }

instead of using the DATA file handle as I did in my example.

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to