How can I print source line number in Perl?
The __LINE__
literal is documented in the Special Literals section of the perldata man page.
print "File: ", __FILE__, " Line: ", __LINE__, "\n";
or
warn("foo");
Note there's a gotcha with
perl -e'warn("foo")'
foo at -e line 1.
if it ends with a newline it won't print the line number
perl -e'warn("foo\n")'
foo
This is documented in "perldoc -f die", but is perhaps easy to miss in the "perldoc -f warn" section's reference to die...