If you are confused about what's in a variable at a certain point, the best solution is to run the script in the debugger, and examine the variables.
perl -d myscript.pl
while start Perl, load and compile the script, and wait for you to type a command. Try h as your first command, it will print a summary of available commands. l to list sections of your script; n to execute a line of code; s to step into a subroutine; r to continue until the current subroutine returns; x to display the value of a variable ... note that you need to backslash true arrays and hashes, to examine a reference to it, to properly see what's happening:
DB<1> $h1; DB<2> $h2 = {} DB<3> $h3 = {has => 'value'} DB<4> x $h1 0 undef DB<5> x $h2 0 HASH(0x8406f78) empty hash DB<6> x $h3 0 HASH(0x8406d08) 'has' => 'value'
h1 is a scalar with no value; h2 is a scalar storing a reference to a hash, but the hash contains no data; h3 is a scalar containing a reference to a hash which has a tag/value pair ... but note that both key and value can be true or false in a boolean sense, and they can both even be undef.
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
In reply to Re: Check for existance & definedness for Hash and Array references
by TomDLux
in thread Check for existance & definedness for Hash and Array references
by kalyanrajsista
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |