0

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**
HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Thomson
  • 20,586
  • 28
  • 90
  • 134
  • It looks like you're trying to embed perl within a batch script. Is that what you're trying to accomplish? – Sobrique Feb 04 '15 at 09:47
  • 2
    Possibly related: http://stackoverflow.com/questions/3062772/can-perl-and-batch-run-in-the-same-batch-file – Sobrique Feb 04 '15 at 09:51

1 Answers1

2

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.

Borodin
  • 126,100
  • 9
  • 70
  • 144