How can I print source line number in Perl?

David Sykes picture David Sykes · Dec 10, 2008 · Viewed 35.2k times · Source

Is it possible to get the current source line number in Perl? The equivalent in C++ is __LINE__.

Answer

Eugene Yokota picture Eugene Yokota · Dec 10, 2008

The __LINE__ literal is documented in the Special Literals section of the perldata man page.

print "File: ", __FILE__, " Line: ", __LINE__, "\n";

or

warn("foo");