Q:

Output correct line number for Perl script wrapped in batch on Windows?

Is there any specifier to tell Perl interpreter that the real Perl scripts starts at some line, then the output will have correct line number from interpreter, like interpret error message? For example, the line number information in below script is incorrect.
@perl -x "%~f0" %*
@exit /b %errorlevel%

#!perl  

use strict;

printxxx "Perl Script\n"; # interpreter will output error for this line with **incorrect line number**

A:

You can use the line directive, which is a special form of comment that looks like # line 99 and dictates the line number that perl will assign to the following line.
For instance
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;

STDOUT->autoflush;

# line 100
say "line ". __LINE__;
die;

output
line 100
Died at E:\Perl\source\line.pl line 101.

It is also possible to add a filename after the line number, which similarly dictates the source file name that perl will report.

