use Tie::Array;
@ISA = qw(Tie::StdArray);
sub FETCH {
my ($self,$index) = @_;
if (ref($self->[$index]) =~ /CODE/) {
return $self->[$index]->();
}
$self->[$index];
}
####
my @MagicItems; tie @MagicItems, main; # main, or the package of your code
@MagicItems = (
"can use all magic items",
"can not use any magic items",
sub { "can only use magic items in the ".random("MITp")." group"},
sub { "can not use magic items in the ".random("MITp")." group"},
sub { "causes $MagicItemGroup[rand @MagicItemGroup] to dysfunction $radius"},
sub { "causes $MagicItemGroup[rand @MagicItemGroup] to loose their power $radius"},
sub { "attracts $MagicItemGroup[rand @MagicItemGroup] $radius"},
sub { "repels $MagicItemGroup[rand @MagicItemGroup] $radius"},
sub { "destroys $MagicItemGroup[rand @MagicItemGroup] $radius"},
);
####
for (1..10) {
print $MagicItems[rand(@MagicItems,)],"\n";
};
####
can not use any magic items
can not use magic items in the Magical Liquids group
can not use magic items in the Musical Instruments group
destroys magic items in the Scrolls group in a 20' radius
repels magic items in the Bags & Bottles group in a 20' radius
causes all magic items to loose their power in a 20' radius
can not use magic items in the Rods group
causes magic items in the Humorous Items group to loose their power in a 20' radius
can only use magic items in the Weird Stuff group
can only use magic items in the Humorous Items group