I would like to get the current filename and line number within a Perl script. How do I do this?
For example, in a file call test.pl:
my $foo = 'bar';
print 'Hello, World!';
print functionForFilename() . ':' . functionForLineNo();
It would output:
Hello, World!
test.pl:3
These are available with the
__LINE__and__FILE__tokens, as documented in perldoc perldata under “Special Literals”: