The second half of a substitution is not a regex, it's a double quotish context, so \s doesn't mean "a space character" (and even if it did \s stands for a lot of different blank chars, not just one) so you want to put a litteral space here. You'll have to put quotes around your code (or it will be broken into several arguments).
And, since it is a double quotish context $ENV{DEBUG} will be replaced straightaway, and you will end up with its value in your code. You should escape the $.
And last thing I saw: unless you use no indentation at all, the print probably isn't the first thing on the line. So you want to allow spaces in front of it. And you probably don't want your code to work on subs that have a name that starts by print, like printfoo
So, with those corrections, you would have: s/^\s+print\b(.*);$/print$1 if \$ENV{DEBUG};/g
Now, that's why it didn't work, but Corion's proposition is a far better idea. You'll avoid adding another modifier to a line that already has one. For exemple print $object->method() if ref $object eq 'Class'; would become print $object->method() if ref $object eq 'Class' if $ENV{DEBUG};, which is a syntax error.
|