Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Perl
use constant planet => 'Earth';
use constant PI => 3.14159;
use constant { RED => 1, BLUE => 2, GREEN => 3 };

Perl's classic way to create constants. For various reasons, module Readonly (or even better, Const::Fast) are now preferred.
use Const::Fast qw(const);
const my $planet => 'Earth';

Module Const::Fast is preferred over Readonly, which is greatly preferred over 'use constant'. Google "Perl Critic Policy Prohibit Constant Pragma" and read the Const::Fast documentation for more details.
planet : constant String := "Earth";

New implementation...
< >
programming-idioms.org