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

Andy Lester andy at petdance.com
Wed Aug 5 11:05:42 PDT 2015


> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20150805/f423b378/attachment.html>


More information about the Chicago-talk mailing list