On Jun 8, 7:33 am, [EMAIL PROTECTED] (Alok Nath) wrote:
>         What is the convention used to declare constants in perl ?
>         In C we declare constant type in Capital letters , not sure
>         how its in perl.

There is a 'constant' pragma in Perl that you can use:
use constant PI => 3.14;

but it is "better" these days to use the Readonly module, available on
the CPAN.  They have several advantages over constants:
1) They can be defined lexically - constants are globals (because
they're implemented as subroutines)
2) They interpolate into strings, because they're real variables
3) You can define Readonly hashes and arrays as well as scalars.

So many people would prefer you abandon the first example I gave, and
replace it with:
use Readonly;
Readonly my $PI => 3.14;

Paul Lalli


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


Reply via email to