加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

为什么我在使用Perl执行Python脚本时没有遇到任何语法错误?

发布时间:2020-12-15 21:29:14 所属栏目:大数据 来源:网络整理
导读:我只是写了一些测试python代码到test.py,我推出它如下: perl test.py 过了一会儿,我意识到了我的错误。我说“过一会儿”,因为 Python代码实际上正确执行,就像在Python解释器! 为什么我的Perl解释我的Python? test.py看起来像这样: #!/usr/bin/python
我只是写了一些测试python代码到test.py,我推出它如下:
perl test.py

过了一会儿,我意识到了我的错误。我说“过一会儿”,因为
Python代码实际上正确执行,就像在Python解释器!

为什么我的Perl解释我的Python? test.py看起来像这样:

#!/usr/bin/python

...Python code here...

有趣的是,如果我做相反的(即调用python something.pl),我得到了大量的语法错误。

解决方法

从 perlrun,

If the #! line does not contain the word “perl” nor the word “indir” the program named after the #! is executed instead of the Perl interpreter. This is slightly bizarre,but it helps people on machines that don’t do #!,because they can tell a program that their SHELL is /usr/bin/perl,and Perl will then dispatch the program to the correct interpreter for them.

例如,

$ cat >a
#!/bin/cat
meow

$ perl a
#!/bin/cat
meow

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读