Yes, this is annoying, and even more so when
defined(@array) and
defined(%hash) become deprecated. The solution I came up with is to use
defined($$name) for scalars, and
defined(*{$name}{THING}) for the others. I think it works on all current Perls without polluting the stash, e.g.
main @> $Test::x = 1; @Test::y = qw(2 3); %Test::z = (a => 'b');
main @> keys %Test::
y x z
main @> join ' ', "SCALARS:", grep defined(${"Test::$_"}), keys %Test:
+:
'SCALARS: x'
main @> join ' ', "ARRAYS:", grep defined(*{"Test::$_"}{ARRAY}), keys
+%Test::
'ARRAYS: y'
main @> join ' ', "HASHES:", grep defined(*{"Test::$_"}{HASH}), keys %
+Test::
'HASHES: z'
main @> join ' ', "SCALARS:", grep defined(${"Test::$_"}), keys %Test:
+:
'SCALARS: x'