Is there a Perl equivalent to Python's `if __name__ == '__main__'`?

前端 未结 3 2086
北恋
北恋 2021-02-06 23:31

Is there a way to determine if the current file is the one being executed in Perl source? In Python we do this with the following construct:

if __name__ == \'__m         


        
3条回答
  •  情话喂你
    2021-02-07 00:05

    unless (caller) {
      print "This is the script being executed\n";
    }
    

    See caller. It returns undef in the main script. Note that that doesn't work inside a subroutine, only in top-level code.

提交回复
热议问题