diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1998-10-21 00:54:14 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-10-21 00:54:14 +0000 |
commit | 779c5bc9b377ace543a8d55375152f3503319113 (patch) | |
tree | f54f44a76f5b98f5b51ba97b65636f9e83e8155d /lib | |
parent | 2ab1b4853ed375afa5dbf2299430175699d0452d (diff) | |
download | perl-779c5bc9b377ace543a8d55375152f3503319113.tar.gz |
restore sanity to "constant" references
p4raw-id: //depot/perl@2029
Diffstat (limited to 'lib')
-rw-r--r-- | lib/constant.pm | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/constant.pm b/lib/constant.pm index 464e20cd91..5d3dd91b46 100644 --- a/lib/constant.pm +++ b/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 |