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. Looks like I need > > some help on this module usage and capabilities. > > Basically the text I am trying to extract is embedded inside two > > tokens (say {}), > > but it can occur anywhere in the input text stream. I tried using > extract_tagged > > function, but that seems to succeed only if the text starts with the tag I > am > > specifying. > > For example, the following example returns expected value (i.e. {abc}): > > > > <snip> > > > > > $text = q{{abc}12345}; > > ($extracted, $remainder) = extract_tagged($text, '{', '}'); > > print "$extracted \n"; > > > > The following example does not (difference is that $text does not > > start with {): > > > > <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? BTW, I seem to be having extracting code block below. There is no output. Here is the code block: #/usr/bin/perl # read the input file for parsing - defered # extract whatever is between covergroups #!/usr/bin/perl #use warnings; use lib "/u/basappas/local/perl/perm_install/lib/perl5/site_perl"; use Text::Balanced qw ( extract_delimited extract_bracketed extract_quotelike extract_codeblock extract_variable extract_tagged extract_multiple gen_delimited_pat gen_extract_tagged ); $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. That is, the code is changed to: #/usr/bin/perl # read the input file for parsing - defered # extract whatever is between covergroups #!/usr/bin/perl #use warnings; use lib "/u/basappas/local/perl/perm_install/lib/perl5/site_perl"; use Text::Balanced qw ( extract_delimited extract_bracketed extract_quotelike extract_codeblock extract_variable extract_tagged extract_multiple gen_delimited_pat gen_extract_tagged ); $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); print "$extracted \n"; Is something wrong with the code? Regards -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/