On Mar 18, 2006, at 20:01, tom arnall wrote:

under 'use strict', how do you assign a value to a constant used only in a subroutine, without doing the assignment with every execution of the sub', and without making the constant a global variable. by constant i mean a
variable which never changes value throughout the script.

Currently Perl has no lexical constants, the idioms to accomplish what you want are this one

   {
       my $fake_constant = 50;

       sub my_syb {
           # closure, uses $fake_constant
       }
   }

and this one

   use Readonly

   sub my_sub {
       Readonly my $CONSTANT => 50;
       # regular sub, uses $CONSTANT
   }

which uses the Readonly module available from CPAN.

-- fxn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to