in reply to Re: Checking for defined-ness for a list
in thread Checking for defined-ness for a list

Hofmator - How would you implement Update2 in a if-check? I like merlyn's solution, but I'm curious how to do it faster ...
  • Comment on Re: Re: Checking for defined-ness for a list

Replies are listed 'Best First'.
Re3: Checking for defined-ness for a list
by Hofmator (Curate) on Jul 25, 2001 at 21:37 UTC

    Well, I thought of something obvious along the lines of:

    my $undefined; while my $key (qw/A B C/) { $undefined = 1, last unless defined $hashref->{$key}; } if ($undefined) { # at least one key undefined } else { # all keys defined }
    I'd say this is faster than the grep/map approach when the list of keys to test is long. It also depends on the probability of a key being undefined. Try and Benchmark some real-life examples and you get a definitive answer concerning the speed.

    -- Hofmator