What does “1;” mean in Perl?

前端 未结 7 778
梦如初夏
梦如初夏 2020-12-24 11:36

I have come across a few Perl modules that for example look similar to the following code:

package MyPackage;

use strict;
use warnings;
use constant PERL510         


        
相关标签:
7条回答
  • 2020-12-24 12:31

    1 at the end of a module means that the module returns true to use/require statements. It can be used to tell if module initialization is successful. Otherwise, use/require will fail.

    $somevar is a variable which is accessable only inside the block. It is used to simulate "static" variables. Starting from Perl 5.10 you can use keyword state keyword to have the same results:

    ## Starting from Perl 5.10 you can specify "static" variables directly.
    sub Somesub {
        state $somevar;
    }
    
    0 讨论(0)
提交回复
热议问题