in reply to Use constant vs. hashes
use strict; package ConstantScalar; use Carp; require Tie::Scalar; @ConstantScalar::ISA = 'Tie::StdScalar'; sub STORE { confess "illegal store into constant"; } # call with a list of refs to scalars sub makeConstant { while (my $ref = shift) { (warn "nonscalar ref", next) if (ref($ref) ne 'SCALAR'); tie $$ref, 'ConstantScalar', $$ref; } } package main; my ($A, $B, $C, $D) = (1, 2, 3, 4); my $E = 5; print "$A $B $C $E\n"; ConstantScalar::makeConstant(\($A, $B, $C, $D)); $E = 123; $A = 4; # illegal store into constant $B = 5; print "$A $B $C $E\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Use constant vs. hashes
by repson (Chaplain) on Jul 03, 2001 at 10:20 UTC | |
by legLess (Hermit) on Jul 03, 2001 at 21:38 UTC | |
|
Re: Re: Use constant vs. hashes
by frag (Hermit) on Jul 03, 2001 at 09:41 UTC |