tags:

views:

67

answers:

2

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?

+2  A: 

<DATA> refers to the DATA filehandle, if you have a __DATA__ section in your code.

I could be wrong, but I believe it also is the proper name for the filehandle you read from with the empty <> operator. (EDIT: I am wrong, that's <ARGV>! Sorry.)

Platinum Azure
+3  A: 

The structure of an error message is:

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

  • message is a description of the error.
  • file is the file where the error occurred.
  • x is the line number in the file where the error occurred.
  • handle is the last file handle read from.
  • y is the last line1 read from the handle.

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.

Michael Carman