How do I use constants from a Perl module?

前端 未结 6 1749
情书的邮戳
情书的邮戳 2020-12-23 11:37

If I define a constant in a Perl module, how do I use that constant in my main program? (Or how do I call that constant in the main program?)

6条回答
  •  难免孤独
    2020-12-23 11:55

    package Foo;
    use Readonly;
    Readonly my  $C1 => 'const1';
    Readonly our $C2 => 'const2';
    sub get_c1 { return $C1 }
    1;
    
    perl -MFoo -e 'print "$_\n" for Foo->get_c1, $Foo::C2'
    

提交回复
热议问题