in reply to Symbol Table entry always return defined for {SCALAR}!!!

You can actually make the sample code more clear, with absolutely no variables defined:

if (defined *{'main::test'}{SCALAR}) { print "scalar" ;} if (defined *{'main::test'}{ARRAY}) { print "array" ;} if (defined *{'main::test'}{HASH}) { print "hash" ;}
This still gives you scalar.

However once you use 'use strict' to disallow symbolic ref, this code throws error. I assume most of the people use 'use strict' all the time, so the failure of this testing is not really that scary.

On the other hand, to some level, it makes sense for this test to be successful for scalar, but not array and hash, as Perl subconsciously take a variable as scalar until it 'knows'.

Replies are listed 'Best First'.
Re: Re: Symbol Table entry always return defined for {SCALAR}!!!
by gmpassos (Priest) on Oct 08, 2003 at 02:26 UTC
    I put the name of the symbol inside an another scalar to explicity do not create the symbol in the table!

    For example, if you have

    package main ; print "$foo" ;
    you will have in the Symbol Table of main an entry for $foo (actually *foo), since the $foo in the print point to a s