in reply to how to identify a null hash value

G'day smartyollie,

There's a semantic issue here. Hashes consist of zero or more pairs of keys and values: talking about a "null hash value" probably isn't what you meant.

I suspect, from the code you've posted, you meant a hash without any key/value pairs. If so, keys will probably do what you want. Here's an example:

#!/usr/bin/env perl -l use strict; use warnings; my %multi = (empty => {}, data => { a => 1 }); for my $key (keys %multi) { if (keys %{$multi{$key}}) { print "Data found in $key"; } else { print "Data not found in $key"; } }

Output:

$ pm_1129100_complex_hash_check.pl Data found in data Data not found in empty

If I haven't guessed correctly, please read "Checking Variable for Not Null". This was posted last week and contains a discussion about NULL not being a Perl concept, per se. Having done that, please reword your question, replacing "null" with undefined, zero-length, FALSE or whatever you feel is most appropriate.

-- Ken

Replies are listed 'Best First'.
Re^2: how to identify a null hash value
by smartyollie (Novice) on Jun 05, 2015 at 17:13 UTC
    What I have is a key/value pair, where the value is a zero-length value. I was referring to that as "null".

      Then you'll want the length() function which can be found in "Perl functions A-Z".

      -- Ken