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


in reply to Re: Help me improve this sub with named params!
in thread Help me improve this sub with named params!

for a slightly nicer version, what about:
my @valid = qw/foo bar baz/; my %args=(stuff); for(@args{@valid}) { next if not defined; }

Replies are listed 'Best First'.
Re: Re: Re: Help me improve this sub with named params!
by blokhead (Monsignor) on Aug 30, 2003 at 05:36 UTC
    I thought of doing something similar, but on the off chance that foobar( valid_arg => undef ); would be actually allowed I wrote what I did. Your code wouldn't be able to distinguish that call from a call that omitted the valid_arg parameter. Also, you'd have to add slightly more code to get key,value pairs (instead of just iterating over the values as you are now). But yours probably is nicer if we don't need to worry about undef parameter values.

    blokhead