perl

What do the line numbers refer to in perl -cw?


When I run "perl -cw" to check syntax for my perl modules and warnings or errors are encountered, two line numbers are given:

perl -cw lib/My/Module.pm
Global symbol "%badvar" requires explicit package name at lib/My/Module.pm line 93, <DATA> line 132.
lib/My/Module.pm had compilation errors.

The "line 93" is the correct position in the source file, but what does "<DATA> line 132" refer to?


Solution

  • The structure of an error message is:

    message at file line x, <handle> line y.

    In your case, the error occurred at line 93 of lib/My/Module.pm, after the 132nd read of the DATA handle. DATA is the built-in handle for reading text after the __DATA__ tag of a source file. Note that line numbers for the DATA handle are skewed. "<DATA> line 132" is the 132nd line after the __DATA__ tag, not the 132nd line of the file.

    1] Technically, it's the value of $.. This is normally a line number but could be something else if you've changed the value of $/. It's also skewed for the DATA handle.