Search code examples
perlpragma

Perl: are there any more directives that may be used in comments?


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?


Solution

  • 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"'