[Chicago-talk] finding *any* defined elements of a hash

Richard Reina gatorreina at gmail.com
Wed Aug 5 13:32:36 PDT 2015


Thanks for all the replies.  I went with Andy's suggestion. But I will keep
in mind all others.

Thanks again.

2015-08-05 13:32 GMT-05:00 Doug Bell <madcityzen at gmail.com>:

> For some other possibilities, see the List::Util module, which has "any"
> and "all".
>
> use List::Util qw( any );
> my $has_a_value = any { defined } values %{ $input_hash };
>
> Though it is a core module, those functions have been added more recently,
> so unless you have a modern Perl, you may need to update the List::Util
> module from CPAN.
>
> Doug Bell
> preaction at me.com
>
> On Aug 5, 2015, at 1:05 PM, Andy Lester <andy at petdance.com> wrote:
>
>
> On Aug 5, 2015, at 1:01 PM, Richard Reina <gatorreina at gmail.com> wrote:
>
> my $input_hash = {
>
>        FName => param('firstname'),
>        LName => param('lastname'),
>        Email => param('email'),
>
>    };
>
> Can I check to see if any of the hash's element is defined without
> checking all the elements as the hash could grow in the future as the
> fields of the form grow.
>
>
> grep through the values and check their count.
>
> my $number_of_defined_values = scalar grep { defined } values
> %{$input_hash};
>
> --
> Andy Lester => www.petdance.com
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20150805/6d54bdbf/attachment.html>


More information about the Chicago-talk mailing list