in reply to How do I restrict a variable to a range of values?

It sounds to me like you want Tie::Hash

my(%hash); tie %hash, 'MyTiedHash'; $hash{a} = 'goodvalue'; # works $hash{b} = 'badvalue'; # error package MyTiedHash; use Tie::Hash; use Carp; use base qw(Tie::StdHash); sub STORE { my($me,$key,$value) = @_; if($value eq 'goodvalue'){ $me->{$key} = $value; }else{ croak("$value not a good value for $key"); } return 1; }

They say that time changes things, but you actually have to change them yourself.

—Andy Warhol

Replies are listed 'Best First'.
Re^2: How do I restrict a variable to a range of values?
by tphyahoo (Vicar) on Jul 27, 2005 at 15:26 UTC
    Yep. That's what I wanted. Thanks!