summaryrefslogtreecommitdiffstats
path: root/contrib/perl5/lib/constant.pm
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>1999-05-02 14:33:17 +0000
committermarkm <markm@FreeBSD.org>1999-05-02 14:33:17 +0000
commit77644ee620b6a79cf8c538abaf7cd301a875528d (patch)
treeb4adabf341898a4378f4b7f8c7fb65f3f7c77769 /contrib/perl5/lib/constant.pm
parent4fcbc3669aa997848e15198cc9fb856287a6788c (diff)
downloadFreeBSD-src-77644ee620b6a79cf8c538abaf7cd301a875528d.zip
FreeBSD-src-77644ee620b6a79cf8c538abaf7cd301a875528d.tar.gz
Maintenance releace 3 of perl5.005. Includes support for threads.
Diffstat (limited to 'contrib/perl5/lib/constant.pm')
-rw-r--r--contrib/perl5/lib/constant.pm14
1 files changed, 14 insertions, 0 deletions
diff --git a/contrib/perl5/lib/constant.pm b/contrib/perl5/lib/constant.pm
index 464e20c..5d3dd91 100644
--- a/contrib/perl5/lib/constant.pm
+++ b/contrib/perl5/lib/constant.pm
@@ -20,6 +20,18 @@ constant - Perl pragma to declare constants
print "This line does nothing" unless DEBUGGING;
+ # references can be declared constant
+ use constant CHASH => { foo => 42 };
+ use constant CARRAY => [ 1,2,3,4 ];
+ use constant CPSEUDOHASH => [ { foo => 1}, 42 ];
+ use constant CCODE => sub { "bite $_[0]\n" };
+
+ print CHASH->{foo};
+ print CARRAY->[$i];
+ print CPSEUDOHASH->{foo};
+ print CCODE->("me");
+ print CHASH->[10]; # compile-time error
+
=head1 DESCRIPTION
This will declare a symbol to be a constant with the given scalar
@@ -86,6 +98,8 @@ constants at compile time, allowing for way cool stuff like this.
print E2BIG, "\n"; # something like "Arg list too long"
print 0+E2BIG, "\n"; # "7"
+Errors in dereferencing constant references are trapped at compile-time.
+
=head1 TECHNICAL NOTE
In the current implementation, scalar constants are actually
OpenPOWER on IntegriCloud