Hi
I am the processing of writing a simple module and my brain just froze.
I am trying to valide data that is being passed to the object constructor
to make sure the arguments are acceptible. The args are being passed as
named arguments.
--
# hash of default or allowed data,
my %_default = (
FILE => 'any_file', # Key has to be FILE, value can be anything
FORM => ['unix_txt', 'htm', 'win_txt'] # key has to be FORM, value
has to be # one
of the items in the array ref
);
# the easy part is validating the the keys in the default hash
# against the keys of the args (%args) being passed to the constructor(new).
foreach my $attr ( keys %_default ) {
my ($argname) = ($attr =~ tr/a-z/A-Z/); # make sure key is
uppercase(like FILE)
if (exists $args{$argname}) # match against %args
{ $self->{$attr} = $args{$argname} } # if the arg key exists
use that
else
{ $self->{$attr} = $self->_default($attr) } # if not use defualt
}
--
now how can I validate the $_default->{FORM} values are one of
['unix_txt', 'htm', 'win_txt'] ??
Thanks for any suggestions and if my question is not clear, please tell me
and I will try to clear it up.
Jim
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]