use warnings; use strict; use Log::Any qw($log); use Log::Any::Adapter ('File', './debug.log'); sub errcheck_array { my $logger = shift; my $prefix = shift; my $count = grep {!defined} @_; # count the number of undefined elements in input array return unless $count; # this line will prevent a log message unless there's an undef; comment it out to log _all_ calls, whether or not there's an undefined value $logger->debugf("%s: %d undefined values found in %s", $prefix, $count, \@_); 1; } foreach my $hr ( [qw(a b c)], [a => undef, b => undef, 'c'], [qw(x y z)] ) { my @HR = @$hr; my $DIcas_text = '%s' . ',%s'x$#HR; errcheck_array($log, "sprintf('$DIcas_text', \@HR)", @HR); my $EVmsg = sprintf($DIcas_text, @HR); print "STD OUTPUT> $EVmsg\n"; }