Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Help modifying recursive regex

by vagabonding electron (Chaplain)
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
Node Status?
node history
Node Type: note [id://1032803]
[Corion]: jthebarg: There is the switch keyword if you want that, but maybe a dispatch table is closer.
[Corion]: If by "case" you meant "case-insensitive ", see fc, uc and lc and perlop on the /i flag ;)
Corion waves to virtualsue
[virtualsue]: I have made a post for the first time in ... years
[marto]: hey virtualsue!
Eily thought about Neko Case first, something might be wrong with my brain's wiring
[virtualsue]: I recommended dbic-migration even though I am having trouble with it this week. It might be my fault.
[ambrus]: wow! I haven't seen you here for a long time, virtualsue
virtualsue waves back
[Eily]: it would have been 2 years in 2 weeks actually. And welcome back virtualsue :)

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (14)
As of 2017-09-26 13:46 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (295 votes). Check out past polls.