Perl-Sensitive Sunglasses | |
PerlMonks |
Re: How do I replace certain character if condition existsby BrowserUk (Patriarch) |
on Apr 17, 2003 at 15:02 UTC ( [id://251224]=note: print w/replies, xml ) | Need Help?? |
This code will correct the gross imbalance of parens without requiring to delete them all. As is, it works line by line, but would operate on a whole file if you slurped it.
All it does is count the number of opens and closes and delete enough of whichever is in excess from the beginning or end to correct any imbalance. In most cases, that probably means that the resultant parenthesizing would not reflect the original intent, but it is difficult to see how to determine what that intent was without specific knowledge. Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong. 2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible 3) Any sufficiently advanced technology is indistinguishable from magic. Arthur C. Clarke.
In Section
Seekers of Perl Wisdom
|
|