CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Matching right and left paranthesis in a long string

 



timewaves
New User

Sep 14, 2010, 8:57 AM

Post #1 of 2 (2277 views)
Matching right and left paranthesis in a long string Can't Post

Hi, the title should say it all

the code I currently have is:

Code
my @right_p = $tree =~ /(\()/g; 
my @left_p = $tree =~ /(\))/g;
print $#right_p == $#left_p ? "YES\n" : "NO\n";


Is there any way of circumventing the use of these two arrays, and truncating this block into one line perhaps?

I have tried comparing both regexs directly but it just compares "1" instead.

Thanks in advance!


shawnhcorey
Enthusiast


Sep 14, 2010, 11:07 AM

Post #2 of 2 (2273 views)
Re: [timewaves] Matching right and left paranthesis in a long string [In reply to] Can't Post

See `perldoc Text::Balanced`.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives