Aquariophile: if $hash{"foo"} returnt false obwohl es nur undef ist

Beitrag lesen

Hallo!

====================================================
Mein Perl-Script.

#!/usr/bin/perl

print "Content-type: text/html\n\n";

my %hash = ( "inge" => "21",
          "tom" => "14",
          "Anna" => "12"
          );

delete $hash{"inge"};
undef $hash{"tom"};

print "The Key <u>inge</u> is NOT True!<br>\n" if $hash{"inge"};
print "The Key <u>tom</u> is NOT True!<br>\n" if $hash{"tom"};
print "The Key <u>Anna</u> is True!<br>\n" if $hash{"Anna"};

====================================================
Die Ausgabe:

The Key Anna is True!

====================================================
Die Frage:

$hash{"inge"} lösche ich ja mit "delete",
dass da     if $hash{"inge"}   false returnt sehe ich ein.

Aber $hash{"tom"} ist doch nur stillgelegt mit "undef"
also sollte der ja grundsaetzlich existieren,
nur eben ohne inhalt, so wie bei  $foo = undef;

Warum der "tom" also Nicht true returnt verstehe ich absolut nicht!!

Das mit $hash{"Anna"} geht wie es sollte.

Danke!
Aquariophile