Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Elegant examples to parse parenthesised strings

by Marshall (Abbot)
on May 19, 2010 at 18:04 UTC ( #840755=note: print w/replies, xml ) Need Help??


in reply to Elegant examples to parse parenthesised strings

I guess another fairly brute force approach..

#!/usr/bin/perl -w use strict; my $line = "05/04/2010 13:09:45 - A - somebody - ( (( my.my id >= 1 )) + ) and ( ( is-relative.to code = 'sister' ) or ( is-relative.to code += 'brother' ) or ( is-mother.to code = 'dog' ) )"; my @terms = $line =~ /\(.*?\)/g; foreach (@terms) { s/.*(\(.*\)).*/$1/; s/^\(\s*//; s/\s*\)$//; print "$_\n"; } __END__ Prints: my.my id >= 1 is-relative.to code = 'sister' is-relative.to code = 'brother' is-mother.to code = 'dog'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://840755]
help
Chatterbox?
[usemodperl]: greetings
[Corion]: marto: Oooh, great! I was on a one week vacation, and in hindsight we should've gone for 10 days or two weeks ;))

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2018-06-20 08:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (116 votes). Check out past polls.

    Notices?