Depending on how complex you want to be, the program may require many changes but taking the simplest approach, I think following will suit your requirements.
#!/usr/bin/perl use strict; 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 ($l_count vs $ +r_count)! Did you format it correctly???"; return 0; } else { print "There is balance in this universe"; return 1; } } my $test_string = 'x = (89 - 12)*( 1 + 2)'; parenth($test_string);
In reply to Re: IT's not counting...
by samarzone
in thread IT's not counting...
by Dwood
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |