Is this a bug in Perl (nested hash)?

C. Abney cabney at cyberpass.net
Wed Apr 12 01:47:12 CDT 2000


~sdpm~
On Tue, 11 Apr 2000, C. Abney wrote:
> On Tue, 11 Apr 2000, John R. Comeau wrote:

> > Checking for the existence of a nested key like $hash{key0}{key00}
> > causes $hash{key0} to exist.  Is that the way it's supposed to work?
> > I would think that merely checking for the existence of
> > $hash{key0}{key00} would not cause $hash{key0} to exist.
> 
> Hmm, that was pretty cryptic (what I said) when I look at it more closely.
> What I meant was, if you use exists to check any of the values (even the
> nested ones) it should return false (unless you have a bug!)

Gawd... maybe I should just wait until someone else answers... I've botched
this.  From 'perlfunc':

defined:
               You may also use defined() to check whether a
               subroutine exists, by saying defined &func without
               parentheses.  On the other hand, use of defined()
               upon aggregates (hashes and arrays) is not
               guaranteed to produce intuitive results, and
               should probably be avoided.

exists:
               Returns TRUE if the specified hash key exists in
               its hash array, even if the corresponding value is
               undefined.
                   print "Exists\n"    if exists $array{$key};
                   print "Defined\n"   if defined $array{$key};
                   print "True\n"      if $array{$key};
               A hash element can be TRUE only if it's defined,
               and defined if it exists, but the reverse doesn't
               necessarily hold true.

CA
-- 
Einstein himself said that God doesn't roll dice. But he was wrong. And
in fact, anyone who has played role-playing games knows that God
probably had to roll quite a few dice to come up with a character like
Einstein.  -- Larry Wall                                     C. Abney

~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list