in reply to Re: Is there a way to lock arrays?
in thread Is there a way to lock arrays?

Wouldn't that also prevent modification of values in the array? I'm not sure that's what the OP wants, but rather just to prevent the array from expanding. It's unclear, but the SetReadOnly function does come with the caveat that you can't modify the array at all.

Larry Wall is Yoda: there is no try{}
The Code that can be seen is not the true Code

Replies are listed 'Best First'.
Re^3: Is there a way to lock arrays?
by BrowserUk (Patriarch) on Jul 07, 2005 at 22:57 UTC

    Sorry. I should have demonstrated that also.

    use Internals qw[SetReadOnly];; @a = 1 .. 3;; SetReadOnly \@a;; print @a;; 1 2 3 $a[ 2] = 'changed';; print @a;; 1 2 changed push @a, 'added';; Modification of a read-only value attempted at SetReadOnly \$a[1];; $a[1] = 'changed';; Modification of a read-only value attempted at

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.