For example:
This prints:my $name = 'main::test' ; if (defined *{$name}{SCALAR}) { print "\$$name\n" ;} if (defined *{$name}{ARRAY}) { print "\@$name\n" ;} if (defined *{$name}{HASH}) { print "\%$name\n" ;}
If you set the array and hash before$main::test
it prints:@test = %test = 1 ;
Soo, it always print true for $main::test!!!$main::test @main::test %main::test
The worst thing is that it always return a scalar reference:
This prints:my $name = 'main::test' ; my $ref = *{$name}{SCALAR} ; print "$ref\n" ;
Soo, it always create a new scalar in the memory, even if you just want to know if the scalar exists in the memory!SCALAR(0x1a6f080)
This was tested with Perl-5.6.1-Win32, Perl-5.8.1-Win32 (the new release), Perl-5.6.1-Linux.
We can see that Devel::Symdump uses
to test if a scalar exists. But if the value of the scalar is undef it's says that the scalar is not in the table. And since *ENTRY{SCALAR} always return a scalar ref it's not needed.if (defined $val && defined *ENTRY{SCALAR}) {
I think that the behavior doesn't work like it should, since for {ARRAY} and {HASH} it works like we want. At least this need to be documented!
Graciliano M. P.
"Creativity is the expression of the liberty".
In reply to Symbol Table entry always return defined for {SCALAR}!!! by gmpassos
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |