Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Help modifying recursive regex

by vagabonding electron (Curate)
on May 09, 2013 at 17:20 UTC ( #1032803=note: print w/replies, xml ) Need Help??

in reply to Help modifying recursive regex

I have tried this with Text::Balanced and it seems to work:

#!/usr/bin/perl use strict; use warnings; use Text::Balanced ':ALL'; while ( my $text = <DATA> ) { my @data = extract_multiple( $text, [ \&extract_bracketed, qr/\s+/ ] ); @data = grep { !/^$/ } map {s/^\s+//;s/\s+$//;s/^\(//;s/\)$//;$_} @data; print join ( '---', @data ), "\n"; } __END__ A A B A B C (A B) C A (B) C A (B C D) A(B C D) A (B C D) E A (B C D)E A (B C D) (E F G) A (B C D) (E F G) I A B (C (D E) (F G)) (H I) A B (C (D E) (F G)) (H I) J A B (C (D E) (F G)) (H I) J K

because it prints:

A A---B A---B---C A B---C A---B---C A---B C D A---B C D A---B C D---E A---B C D---E A---B C D---E F G A---B C D---E F G---I A---B---C (D E) (F G)---H I A---B---C (D E) (F G)---H I---J A---B---C (D E) (F G)---H I---J---K

There is an issue though (perhaps due to my lack of deep knowledge of the module). If I put a line print  $@->{error}, "\n" if $@; after the first line in the loop it prints Did not find opening bracket after prefix: "\s*" every time. Is this something to worry about or just to take note of?

Just my 2 cents.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2022-12-08 01:46 GMT
Find Nodes?
    Voting Booth?

    No recent polls found