At 09:06 AM 9/25/01 -0400, Kipp, James wrote:

> >
> > >
> > >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.
>
>The user will not populate the %_default.

Right, that's what I meant, you're populating it.  So I don't see that you 
need to use code to make sure that you put the keys in uppercase.

>That hash is there to provide
>default values and make sure the args passed our allowable. The args being
>passed to the constructor will go into %args. So if the user creates and
>object like this:
>my $log = new Logs (FILE => 'mylogfile',
>                           FORM => 'htm'
>);
>%args will not contain: FILE => 'mylogfile',FORM => 'htm'

"not"?  I think you mean "now".

>so the reason I do the tr/// is to make sure the arg key FILE and FORM are
>uppercase.
>
> >
> > >       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,
>
>woops, that was a typo, is should be:
>{ $self->{$attr} = $self->$_default($attr) }

I don't think so, that would call the method named by the scalar $_default 
and pass it $attr as argument.  I think you mean

         $self->{$attr} = $_default{$attr}

since you have shown no code to suggest that _default is in instance data, 
and I wouldn't expect it to be.

> >
> > >--
> > >now how can I validate the $_default->{FORM} values are one of
> >
> > I thought you were validating %args, not %_default.
>
>yes, right, another damn typo sorry. I am tryint to validate %args against
>%_default
>
>
> >
> > >['unix_txt', 'htm', 'win_txt'] ??
> >
> > Suggest instead defining it as
> >
> >          FORM => { unix_txt => 1, htm => 1, win_txt => 1 }
>
>so make a hash of hashes ?

Yes.

> >
> > and then you can test
> >
> >   if ($_default{FORM}{$args{$argname}}
>
>hmm, that might work. I will give it a try.
>
>Thanks for the help
>Jim

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to