define regex in prefix of Text::Balanced functions

W

Wenjie

Hello,


I have a task to check things within some block in a file:
----%<-----
# this is the block to be analyzed:
{
Item one;
Item two
} quantity: 3
----%<-----

I want to get:
a):
Item one;
Item two
b): a) has quantity 3


Text::Balanced seems to be useful but I have met the problem to
specify "prefix":

use Text::Balanced qw(extract_bracketed);
use strict;

my $objfile = shift;
open (PAT, "< $objfile") or die "couldn't open $objfile for reading: $!\n";

my $text;
{
local $/;
$text = <PAT>;
}
my ($extracted, $remainder) =
extract_bracketed ($text, '{', "What_to_fill_here_?");

# What to do to extract quantity for the block?


Thanks for your helps,
Wenjie
 
A

Anno Siegel

Wenjie said:
Hello,


I have a task to check things within some block in a file:
----%<-----
# this is the block to be analyzed:
{
Item one;
Item two
} quantity: 3
----%<-----

I want to get:
a):
Item one;
Item two
b): a) has quantity 3


Text::Balanced seems to be useful but I have met the problem to
specify "prefix":

use Text::Balanced qw(extract_bracketed);
use strict;

my $objfile = shift;
open (PAT, "< $objfile") or die "couldn't open $objfile for reading: $!\n";

my $text;
{
local $/;
$text = <PAT>;
}
my ($extracted, $remainder) =
extract_bracketed ($text, '{', "What_to_fill_here_?");

# What to do to extract quantity for the block?

It is in $remainder (with a leading blank). What is the problem?

Since you don't say how your text sample might be embedded in other
text, it is impossible to say more.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top