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



timewaves
New User

Sep 14, 2010, 8:57 AM


Views: 5922
Matching right and left paranthesis in a long string

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


Views: 5918
Re: [timewaves] Matching right and left paranthesis in a long string

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".