Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Perl constants

You can even write your own module that works like the charnames pragma but defines character names differently. However, the interface to that is still exper- imental, so see the manpage for the latest. constant use use use use use use use constant constant constant constant constant constant constant

BUFFER_SIZE ONE_YEAR PI DEBUGGING ORACLE USERNAME USERINFO => => => => => => => 4096; 365.2425 * 24 * 60 * 60; 4 * atan2 1, 1; 0; '[email protected]'; scalar getpwuid($<); getpwuid($<);

use constant { BUFFER_SIZE ONE_YEAR PI DEBUGGING ORACLE USERNAME USERINFO }; => => => => => => => 4096, 365.2425 * 24 * 60 * 60, 4 * atan2( 1, 1 ), 0, '[email protected]', scalar getpwuid($<), getpwuid($<), sub deg2rad { PI * $_[0] / 180 }

print "This line does nothing" # references use constant use constant use constant print print print print unless DEBUGGING; can be declared constant CHASH => { foo => 42 }; CARRAY => [ 1,2,3,4 ]; CCODE => sub { "bite $_[0]\n" }; CHASH­>{foo}; CARRAY­>[$i]; CCODE­>("me"); CHASH­>[10]; # compile­time error

This pragma declares the named symbol to be an immutable constant 2 with the given scalar or list value. Values are evaluated in list context. You may override this with scalar as we did above. Giving it a hash reference declares many con- stants at once with only one use statement.

Since these constants don't have a $ on the front, you can't interpolate them directly into double-quotish strings, although you may do so indirectly:

print "The value of PI is @{[ PI ]}.\n"; 2. Implemented as a subroutine taking no arguments and returning the same constant each time. 1012 | Chapter 29: Pragmatic Modules