in reply to Re: Check for variable without leaving a trace
in thread Check for variable without leaving a trace

This isn't what I'm trying to do. I want to check whether a program has used the variable %hash without creating it. You used to be able to do this with defined, but someone thought it would be a good idea to deprecate that. exists $::{hash} can tell you whether one or more of $h, &h, %h, @h is defined, but not which.

Replies are listed 'Best First'.
Re^3: Check for variable without leaving a trace
by Fox (Pilgrim) on Dec 09, 2009 at 16:03 UTC
    hm, now I get it.
    but I think not even perl can tell that ( $h was used and %h was not, for example)
      It mostly can (or at least could before 5.11), using defined:
      main @> $test = 1 1 main @> defined $test 1 main @> defined %test '' main @> %test2 = 1,2 1 2 main @> defined $test2 '' main @> defined %test2 1 main @> %test3 = () undef main @> defined %test3 '' main @> defined $test3 ''
      It doesn't detect an empty hash, but that's good enough for me.
        no, I meant, perl can tell if $a or %a is defined but given 'a' it can't say which one was used.