Simplified return value and shortened code by avoiding needless use of $_:
sub balanced { (my $s = shift) =~ s/[^()]//g; eval "qw($s); 1" }
Or in 5.14+:
sub balanced { my $s = shift =~ s/[^()]//rg; eval "qw($s); 1" }
In reply to Re^3: Using qw to check for balanced parentheses (oops)
by ikegami
in thread Using qw to check for balanced parentheses
by unix_hacker_beard
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |