Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Text::Balanced not extracting

by kcott (Archbishop)
on Oct 16, 2010 at 20:58 UTC ( [id://865730]=note: print w/replies, xml ) Need Help??


in reply to Text::Balanced not extracting

You need to specify a prefix.

Change

extract_bracketed($text,'()')

to

extract_bracketed($text,'()', '%%% rick ran errands . sem')

and you'll get your expected output.

This is explained in the Text::Balanced documentation.

-- Ken

Replies are listed 'Best First'.
Re^2: Text::Balanced not extracting
by cormanaz (Deacon) on Oct 16, 2010 at 22:35 UTC
    Yeah I saw that but wasn't too sure what they meant by a prefix. I wonder why they built the module that way. Seems like there would be cases you'd want to use something like this were the "prefix" wouldn't be known in advance.

      I haven't used this module before today so I can't offer any deep insight into the ways things have been set up.

      I did wonder (exactly as you have) why it's set up like this.

      I've just successfully tried the following:

      my ($extracted,$remainder) = extract_bracketed($text,'()', ($text =~  m{ \A ( [^(]+ ) }msx)[0]);

      You might choose to use something like that in all cases that might have an unknown prefix.

      I haven't checked out the solution below (by Khen1950fx) - that may be preferable.

      -- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://865730]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-03-29 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found