in reply to Test if a subhash in a referenced hash exists

"Can't use string ("") as a HASH ref while "strict refs" in use

That error results from trying to evaluate an empty string as a hash reference.  In other words, the part you have in between %{...} most likely evaluates to the empty string, instead of the hashref that would be needed here:

use strict; use warnings; my $data = {}; $data->{foo} = { a => 1}; $data->{bar} = ""; if ( %{ $data->{foo} } ) { ... } # ok, because $data->{foo} is a has +href if ( %{ $data->{bar} } ) { ... } # not ok, because $data->{bar} is e +mpty

Best is probably to directly test whether the value in question is a hashref, i.e.

if ( ref($data->{bar}) eq "HASH" ) { ... } # ok, even if $data->{bar +} is empty/undef

or, adapted to your example:

... next unless ref($coordinates->{$group}{$id}{$stage}{"coords"}) eq +"HASH"; # print individual and coordinate information

See ref.

Replies are listed 'Best First'.
Re^2: Test if a subhash in a referenced hash exists
by Henri (Novice) on May 29, 2010 at 13:24 UTC
    The empty string crept in since I had a legacy line in my code that set $coordinates = “” <grmpf>. I am trying to clean up a script that has grown over the past years. I had tried ref, but it had not worked, probably due to my notation confusion. Your %{$data->{foo}} notation is another variant to the ones I just posted.