Sharan Basappa wrote:
On Wed, Apr 23, 2008 at 8:33 PM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote:
Sharan Basappa wrote:
I have gone through the text-balanced doc and tried few examples
myself.

<snip>

$text = q{12{abc}12345};
($extracted, $remainder) = extract_tagged($text, '{', '}');
print "$extracted \n";

 You need a prefix pattern as the fourth argument, e.g. '[\w\s]+'

The other question I have is that I would like to use text-balanced
module to extract multiple
occurences of these strings that are tagged by these tokens. Is that
possible?

 Use the extract_multiple() function.

Thanks, Gunnar. So I am assuming that extract_tagged is fine, but it
should go into extract_multiple. Is that correct?

Yes.

BTW, I seem to be having extracting code block below.
There is no output. Here is the code block:

<snip>

#use warnings;

Don't comment out the warnings pragma, and include "use strict;"!

$source = " covergroup cg @(posedge clk);
  coverpoint v_a
  {
    bins sa = 0 => 1 => 2 => 0;
    bins sa = 0 => 1 => 0;
  }
endgroup";

($extracted, $remainder) = extract_tagged($source, covergroup, endgroup,
'[\w\s]*');
print "$extracted \n";

I remove the 4th arg and I see proper output.

The prefix pattern seems to be greedy. Try: '.*(?=covergroup)'

OTOH, I don't see the point in struggling with Text::Balanced, when all you need is:

    my @extracted = $source =~ /covergroup.+?endgroup/gs;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

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


Reply via email to