How do I comment a part of a single line in Perl, like the following line:
if($clevel==0){#never happends}
I would like to be able to comment that last closing bracket, without going to a new line.
How do I comment a part of a single line in Perl, like the following line:
if($clevel==0){#never happends}
I would like to be able to comment that last closing bracket, without going to a new line.
A #
and then a line break. You can treat them as a bracket of sorts, since little in Perl looses its meaning from being on different lines.
my $ans = 2 + rand( 5 ) + $pixels / FUDGE_FACTOR;
To
my $ans = # 2 +
rand( 5 ) + $pixels # / FUDGE_FACTOR
;
Or from:
if ( dont_know_how_this_breaks() && defined $attribute ) {
#...
}
To:
if ( # dont_know_how_this_breaks() &&
defined $attribute ) {
#...
}
If it's really that important, use source filtering.
# C_Style_Comments.pm
package C_Style_Comments;
use Filter::Simple;
FILTER { s{/\* .* \*/}{}gmx };
1;
$ perl -MC_Style_Comments -e 'print /* 5, No wait, I mean */ 3'
3
Any reason you can't write :
if($clevel==0){#never happends}
as :
if($clevel==0){} #never happens
There are some tricks you can do to hide messages, such as:
0 and 'some comment'
But you're just going to make it more confusing if someone else has to maintain your code in the future.
Working within the constraints of a language, rather than trying to force it to act like some language you're more familiar with often leads you to learn new things. I personally hate working in IDL, but some of the tricks for dealing with poor loop performance led me to optimize code I've since written in other languages.