Question

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?

Was it helpful?

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top