in reply to IT's not counting...
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: IT's not counting...
by Dwood (Acolyte) on Nov 16, 2010 at 08:47 UTC | |
by samarzone (Pilgrim) on Nov 16, 2010 at 09:28 UTC | |
by Dwood (Acolyte) on Nov 16, 2010 at 09:47 UTC |