Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: only allow certain parameters

by Ovid (Cardinal)
on Aug 09, 2002 at 22:45 UTC ( #189082=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://189082]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (1)
As of 2023-01-29 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?