http://qs321.pair.com?node_id=189082


in reply to only allow certain parameters

Right off the bat, this is what I thought of:

sub balance_by { my ($self,$entry) = @_; my %valid_params = map {$_ => 1} qw/ foo bar /; $self->{'balance_by'} = (defined $entry and exists $valid_params{$ +entry}) ? $entry : 'foo'; return $self->{'balance_by'}; }

The only real change is the removal of the unless logic. What that does is set the "balance_by" if you have a valid $entry>, else it sets it to the default "foo". However, it seems to me that you wanted a one-time setting of balance_by that could not be changed. Is that correct? In your code "foo" will only be used as a default on the first pass.

So, if I understood what you wanted, my code will always set balance_by to $entry if you have a valid $entry. If it's not valid, it sets it to "foo".

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.