"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.
In reply to Re: Test if a subhash in a referenced hash exists
by almut
in thread Test if a subhash in a referenced hash exists
by Henri
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |