Forum Moderators: coopster
Usually when there's some code in a script that you want to take out, you can "comment it out" (prepend "//" to the line), or just delete the stuff. This developer's favourite method is to enclose the code with:
if (false){
command, command, etc.
}
It's infuriating! I'm going through pages of stuff trying to figure out what it's supposed to do, wondering why there are obvious syntax errors, trying to figure out why it's not working, and ... then I notice these subtle "if" statements scattered throughout like dandruff.
Sheesh!
I myself am occasionally guilty of this abomination against Perl (but I try to expunge it before I set the code loose):
=pod
"commented" out code
=cut
Speaking of Perl, your problem looks like a job for regular expressions. I've got to step into a meeting, but I'll try to get back to you with a way to clean up your code in a hurry.
If you don't do Perl, this could ported to PHP pretty easily.
#!/usr/bin/perl -w
undef $/;
while (<>) {
s#if\s*\(\s*false\s*\)\s*\{[^\{\}]*(\{[^\}]+\})*[^\{\}]*\}##gs;
print
}
I must confess I do things like while debugging code - but if it got in to a release I'd be mortified! sneaking away ... > grep if (false)
However, it IS a convenient way to comment out larger blocks of code when they contain other comment blocks. I find this happening most when the client can't make up their mind about whether to do something one way or the other. Or their "final decision" is likely to be reversed.
As everyone has said though - it shouldn't find its way into production code.
btw - I often find this accompanied by a s**tload of older file versions that have names including "temp", "old", "backup", "temp2", etc. A good source control app is in need when you start running into this.