Sprad has asked for the wisdom of the Perl Monks concerning the following question:

I use (Windows NT) batch wrappers on a lot of my perl scripts. It's a convenient way to run perl scripts on machines that don't have perl installed.

The problem comes when debugging these scripts. The wrapper bit (usually 5-10 lines, depending on the task) counts towards the line count, so when perl says I have an error on line 85, it actually means line 93.

Is there a way to set the line count to a different value to fix this problem? I seem to remember seeing this somewhere, but I haven't been able to find it...

---
A fair fight is a sign of poor planning.

Replies are listed 'Best First'.
Re: Line numbers in error messages
by dws (Chancellor) on Oct 03, 2002 at 18:20 UTC
    Is there a way to set the line count to a different value to fix this problem? I seem to remember seeing this somewhere, but I haven't been able to find it...

    You're thinking of the #line directive, which is documented in perlsyn, which reads, in part:

    Much like the C preprocessor, Perl can process line directives. 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 the same as for most C preprocessors: it matches the regular expression /^#\s*line\s+(\d+)\s*(?:\s"([^"]+)")?\s*$/ with $1 being the line number for the next line, and $2 being the optional filename (specified within quotes).
Re: Line numbers in error messages
by BrowserUk (Patriarch) on Oct 03, 2002 at 18:20 UTC

    The directive is #line 15, any message produce on the line after this will be reported as line 15, line 16 for the next and so on. If you have AS, it would be much easier to us the pl2bat.bat command that comes with the distribution. Look in x:\perl\bin or where ever you have your perl installed.

    It builds a bat from the .pl and adds the appropriate #line nn bit for you.

    If you have AS 5.6.1, modify the url behind this [file://localhost/X:/perl/html/faq/Windows/ActivePerl-Winfaq4.html] to reflect your installation and it will take you to the documentation of pl2bat and other good stuff


    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!
Re: Line numbers in error messages
by perrin (Chancellor) on Oct 03, 2002 at 18:21 UTC
    ... some code ... #line 27 ... some code ...