I would like to get the current file name and line number in a Perl script. How to do it?
For example, in a file call test.pl:
test.pl
my $foo = 'bar'; print 'Hello World'; print functionForFilename() . ':' . functionForLineNo();
It outputs:
Hello World test.pl:3
They are available with tokens __LINE__and __FILE__, as described in perldoc perldata in the "Special Literals" section:
__LINE__
__FILE__
The special literals __FILE__, __LINE__, and __PACKAGE__ represent the current file name, line number, and package name at this point in your program. They can only be used as separate tokens; they will not be interpolated into strings. If there is no current package (due to an empty package, directive), __PACKAGE__ is the value undefined.
caller , :
caller
sub print_info { my ($package, $filename, $line) = caller; ... } print_info(); # prints info about this line
, sub, , , , . __FILE__ __LINE__ , , . ( , , , )
You can use:
print __FILE__. " " . __LINE__;
Source: https://habr.com/ru/post/1772520/More articles:С++: чтение из файла с нулевыми символами - c++MySQL Error 1054: Unknown column in a sentence - sqlreading large command output using clojure - clojureIs it faster to allow PHP to parse a large file than calling data from a MySQL database? - performanceDoes AVAssetReader not read the entire file? - iosIs it possible to implement a vertical scrollbar in a drop-down menu using only CSS? - javascriptOptimization: access to fields against methods - optimizationIE8 gives the error "Invalid argument" when using prototype.js, how to find where the error is? - javascriptXML output from JSF2 using Facelets - java-eeChange table row color if checked using CSS3 selectors? - cssAll Articles