Is it possible to get the current source line number in Perl? The equivalent in C++ is __LINE__
.
Using the special Perl variable $! in the message passed to die. You display the current line of execution in a Perl script by referring to it with the __LINE__ token. You display the name of the current Perl package with __PACKAGE__. or die $!
The Perl print function\n"; Notice that you need to supply the newline character at the end of your string. If you don't supply that newline character, and print multiple lines, they'll all end up on one long line of output, like this: Hello, world.
$$ - The process number of the Perl running this script. $0 - Contains the name of the program being executed.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With