获取perl脚本的当前行行号和脚本名称的代码

发布时间:2019-12-04编辑:脚本学堂
获取perl脚本的当前行行号和脚本名称的代码,供大家学习参考。

获取perl脚本的当前行行号和脚本名称的代码,供大家学习参考。
 

复制代码 代码如下:
#!/usr/bin/perl
# Program, named literals.perl, written to test special literals
print "We are on line number ", __LINE__, ".n";
print "The name of this file is ",__FILE__,".n";
__END__
    And this stuff is just a bunch of chitter–chatter that is to be
    ignored by Perl.
    The __END__ literal is like Ctrl–d or 04.[a]

(Output)
1   We are on line number 3.
2   The name of this file is literals.perl.

Explanation
The special literal _ _LINE_ _ cannot be enclosed in quotes if it is to be interpreted. It holds the current line number of the Perl script.
The name of this script is literals.perl. The special literal _ _FILE_ _ holds the name of the current Perl script.
The special literal _ _END_ _ represents the logical end of.