At 05:04 PM 9/24/01 -0400, Kipp, James wrote:
>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)
But you get to populate %_default, right? So you can make sure that the
keys are uppercase. I don't understand why you do this tr.
> 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
>}
I assume that _default is a method that accesses %_default, but that means
that %_default is defined in some other method that you haven't show
us. This is most confusing.
>--
>now how can I validate the $_default->{FORM} values are one of
I thought you were validating %args, not %_default.
>['unix_txt', 'htm', 'win_txt'] ??
Suggest instead defining it as
FORM => { unix_txt => 1, htm => 1, win_txt => 1 }
and then you can test
if ($_default{FORM}{$args{$argname}}
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]