
Array::Lock- Subroutines to make Arrays read-only.

use Array::Lock qw(lock_indexes unlock_indexes
lock_value unlock_value
lock_array unlock_array);
@array = qw/f o o b a r/;
@indexes = qw/1 2 4/;
lock_values (@array);
lock_values (@array, @indexes);
unlock_values (@array);
lock_indexes (@array);
unlock_indexes (@array);
lock_array (@array);
unlock_array (@array);

Array::Lock contains functions to lock an array.
By default Array::Lock does not export anything.
Perl 5.8.0 (inadvertantly for arrays?) introduces the ability to restrict an array to a range of indexes... No indexes outside of these can be altered.. It also introduces the ability to lock an individual index so it cannot be deleted and the value cannot be changed.
lock_indexes(@array);
Restricts the given arrays indexes to its current amount. No more indexes can be added; however, the values of current indexes can be changed. exists() will still work, but delete() will not, as its standard behavior is to get rid of the current index. Note: the current implementation prevents bless()ing while locked. Any attempt to do so will raise an exception. Of course you can still bless() the array before you call lock_indexes() so this shouldn't be a problem.
Right now, lock_indexes does not function with a range. However, if I get feedback that sugests that a range is desired, a hack of some sort may be possible.
unlock_indexes(@array);
Removes the restriction on the array's indexes.
lock_values (@array, @indexes); lock_values (@array); unlock_values (@array, @indexes);
Locks and unlocks index value pairs in an array. If no set of indexes is specified, then all current indexes are locked.
lock_array(@array);
lock_array() locks an entire array, making all indexes and values readonly. No value can be changed, no indexes can be added or deleted.
unlock_array(@array);
unlock_arrray() does the opposite of lock_array(). All indexes and values are made read/write. All values can be changed and indexes can be added and deleted.

Gyan Kapur, <gkapur@cpan.org>
This is really just Schwern's code, although he doesn't know it...

Copyright 2003 by Gyan Kapur
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.