develooper Front page | perl.perl6.users | Postings from December 2019

Re: modules and constants

Thread Previous
From:
ToddAndMargo via perl6-users
Date:
December 6, 2019 11:07
Subject:
Re: modules and constants
Message ID:
6c8b4e4c-bd2f-fb42-4289-477f55abea56@zoho.com
>> On Fri, 6 Dec 2019 at 09:05, ToddAndMargo via perl6-users 
>> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>> 
>>     On 2019-12-06 00:01, Tom Blackwood wrote:
>>      > Todd,
>>      >
>>      > AFAIK Perl’s culture is not to use so many constants in actual
>>      > programming. :)
>>      >
>>      > Tom
>>      >
>> 
>>     Is there a way to make constants universal inside a module, or
>>     do I have to declare them inside every sub?

On 2019-12-06 01:39, Simon Proctor wrote:
> If you define them in the top level of your module then all your subs 
> have access :
> 
> constant FOO = 2;
> 
> sub inc-by-foo( $a ) {
>    $a+FOO;
> }
> 

Do you mean

     sub inc-by-foo( $a ) is export {
        $a+FOO;
     }
?

I tried that several years ago and had no joy.  I
had to put the constants inside the sub for the sub
to see them.   Is this a change?

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About