Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Problem with Text::Balanced

by darobin (Monk)
on Apr 25, 2001 at 20:02 UTC ( #75510=perlquestion: print w/replies, xml ) Need Help??

darobin has asked for the wisdom of the Perl Monks concerning the following question:

I'm having trouble with Text::Balanced::extract_bracketed and I'm hoping someone here could tell me whether it's a bug in the way I use it, in the fact that I use (it can't be done with it), or in the module itself.

I have the following sample data:

{ prop: "\ value"; }

As you probably know, that's valid CSS syntax. I'm trying to extract that block from the CSS (It's at the beginning of the string at the moment when I'm calling what follows) with:

($foo,$bar,undef) = Text::Balanced::extract_bracketed($css,q/{}'"/,qr/ +\s*/);

I tried variations on the above, but it never seemed to work: the text doesn't get extracted. TIA for any help.

-- darobin -- knowscape 2 coming soon --

Replies are listed 'Best First'.
Re: Problem with Text::Balanced
by darobin (Monk) on Apr 25, 2001 at 21:56 UTC

    I think I've found the bug in Text::Balanced. On line 236 (v1.83) there's a regex that only had the /gc flags. Adding /s seems to fix it. I'm not sure it's the right fix, I'm submitting to Damian.

    UPDATE: I just received a mail from Damian confirming that there was a problem, and that the fix will be in the next release.

    UPDATE 2: Text::Balanced 1.84 is out with the fix incorporated. CSS::SAC users take notice, version 0.04 to come will require that version of Text::Balanced.

    -- darobin -- knowscape 2 coming soon --

Re: Problem with Text::Balanced
by nardo (Friar) on Apr 25, 2001 at 21:12 UTC
    You are using q/{}'"/ for your delimiter. This is incorrect, the quotes around "value" are not a delimiter, only the braces are.
    extract_bracketed($css, '{}')
    should work for you. Note that you really only need '{' or '}' as the delimiter, I just happen to find '{}' more legible.

      Yes I do need the " and ' because those must be balanced too. I don't want { "}" } to do the wrong thing. Quotes must be balanced here too, and yes } can happen between quotes on the rhs.

      In any case, taking away the quotes doesn't change anything. It's in the way Text::Balanced handles \n somehow, I'm nearly there.

      -- darobin -- knowscape 2 coming soon --

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2023-02-06 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (33 votes). Check out past polls.

    Notices?