문제

AFAIK, you can use the following directive in comments to set the line number:

#!/usr/bin/perl
# line 42000
die "Debug me if you can!";

which will produce:

Debug me if you can! at script.pl line 42000.

Are there any more similar directives, that start with '#', in Perl?

도움이 되었습니까?

해결책

The following section of perldoc discusses that: perlsyn - Plain Old Comments (Not!)

Perl can process line directives, much like the C preprocessor. Using this, one can control Perl's idea of filenames and line numbers in error or warning messages (especially for strings that are processed with eval()). The syntax for this mechanism is almost the same as for most C preprocessors: it matches the regular expression. ...

You can change the line number and filename for error and warning messages, nothing else: # line 42 "new_filename.plx"'

다른 팁

The shebang line is parsed by the Perl interpreter, even on systems like Windows that don't respect the shebang line. Perl will recognize just about any command line switch (except -M). Examples:

#!/usr/bin/perl -w                  enable warnings
#!/usr/bin/perl -T                  enable taint mode
#!/usr/bin/perl -Ifoo -Ifoo/lib     add directories to @INC
#!/usr/bin/perl -F -n               wrap the script in  while(<>){@F=split; ...}

Perhaps you'd like to take a look at Smart::Comments.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top