My program is trying to read from a line and count the number of parentheses however, as you can see it's not working very well: My code runs, but does not work, as no matter what either both l_count and r_count are the same or it throws an error about the parentheses not being balanced properly...
How do I count the # of Parentheses in a string?
Edit: samarzone fixed me up right and showed me what I was doing wrong. It has thus been fixed:
sub parenth {
my ($string) = (@_);
my $l_count = () = ($string =~ /\(/g);
my $r_count = () = ($string =~ /\)/g);
if ($l_count != $r_count) {
print "There is no balance on this line! Did you format it
+ correctly???";
return 0;
}
else {
print "There is balance in this universe";
return 1;
}
}
Any thoughts on how to implement such parsing methods without regex (is that even possible?)
Or just ideas in general for uses, as such?