Is it possible to get the current source line number in Perl?
The equivalent in C++ is __LINE__
.
views:
1855answers:
3
+16
A:
print "File: ", __FILE__, " Line: ", __LINE__, "\n";
or
warn("foo");
eed3si9n
2008-12-10 09:01:07
warn will print on STDERR.
mat
2008-12-10 09:04:16
+4
A:
The __LINE__ literal is documented in the Special Literals section of the perldata man page.
converter42
2008-12-10 14:07:02
+2
A:
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...
bigiain
2008-12-11 02:34:26