On Tue, Oct 14, 2008 at 8:50 PM, Rob Dixon <[EMAIL PROTECTED]> wrote:
> 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
>
Thanks, Rob. I am aware that a file descriptor needs to be opened etc.
BTW, do you think text-balanced can help in situations that are slightly
more complex than I described above. For example, if I have data like:
keywordx id
some text
some text
{
more text
more text
}
I would like to extract starting from keywordx till closing braces.
Add to this, there will be multiple instances of such code pieces in the
input I am trying to process.
I looked at text-balanced but could not find anything that would help in doing
the above task.
Thanks once again ...
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/