Mailing List Archive

Pointer syntax question
I've a feeling that I have a basic misunderstanding here:

First I create the following (actually part of an object, but this
is just a minimal test program:

$db = {};
$db->{'ConnectNameIndex'} = {};
print "\ndb> ";
print ref $db;
print "\nStored pointer> ";
print ref ($db->{'HostNameIndex'});
print "\n";

When I print the first item, I get what I expect:

db> HASH

But the second item does not do what I expect - to me it looks
identical to the first case except that I've shoved the pointer
to a hash into a hash:

Use of uninitialized value at test2 line 25.
Stored pointer>

BTW, line 25 in my file was
print ref ($db->{'HostNameIndex'});


Can someone explain to me where I've gone off into hyperspace?
Re: Pointer syntax question [ In reply to ]
On Wed, 6 Sep 1995, Dale Amon wrote:

> I've a feeling that I have a basic misunderstanding here:
>
> First I create the following (actually part of an object, but this
> is just a minimal test program:
>
> $db = {};
> $db->{'ConnectNameIndex'} = {};
> print "\ndb> ";
> print ref $db;
> print "\nStored pointer> ";
> print ref ($db->{'HostNameIndex'});
^^^^^^^^^^^^^--------ConnectNameIndex maybe?
> print "\n";
>
> When I print the first item, I get what I expect:
>
> db> HASH
>
> But the second item does not do what I expect - to me it looks
> identical to the first case except that I've shoved the pointer
> to a hash into a hash:

Mike

--
Mike Stok | The "`Stok' disclaimers" apply.
stok@pencom.com | Pencom Systems Administration (work)
stok@cybercom.net | Cyber Access (play)
http://www.cybercom.net/~stok/ | The inevitable WWW page (?)
Re: Pointer syntax question [ In reply to ]
>>>>> Dale Amon writes:

Dale> I've a feeling that I have a basic misunderstanding here:
Dale> First I create the following (actually part of an object, but this
Dale> is just a minimal test program:

Dale> $db = {};
Dale> $db->{'ConnectNameIndex'} = {};
Dale> print "\ndb> ";
Dale> print ref $db;
Dale> print "\nStored pointer> ";
Dale> print ref ($db->{'HostNameIndex'});
Dale> print "\n";

Dale> When I print the first item, I get what I expect:


Dale> But the second item does not do what I expect - to me it looks
Dale> identical to the first case except that I've shoved the pointer
Dale> to a hash into a hash:

Dale> Use of uninitialized value at test2 line 25.
Dale> Stored pointer>

Dale> BTW, line 25 in my file was
Dale> print ref ($db->{'HostNameIndex'});


Dale> Can someone explain to me where I've gone off into hyperspace?


Shouldn't 'ConnectNameIndex' and 'HostNameIndex' be the
same name? If you change the second to the last line from:

print ref ($db->{'HostNameIndex'});

to

print ref ($db->{'ConnectNameIndex'});

the output becomes


db> HASH
Stored pointer> HASH

which is what I guess you are expecting. If you want to handle
undefined entries, try something like

print defined $db->{'HostNameIndex'} ? ref ($db->{'HostNameIndex'}) : '(undefined)';

Hope this helps.
-Dave
Re: Pointer syntax question [ In reply to ]
Oopps, I lifted the wrong part of the test program - I was trying it
with two different parts of the same structure. Here is the entire
thing and the entire output:

#!/usr/local/bin/perl -w

$db = {};
$db->{'HostnameIndex'} = {};

print "db> ";
print ref ($db);
print "\na> ";
print ref ($db->{'HostNameIndex'});
print "\nb> ";
print ref (\$db->{'HostNameIndex'});
print "\nc> ";
print ref (\($db->{'HostNameIndex'}));
print "\n";

---------

>test2
Use of uninitialized value at test2 line 9.
a>
b> SCALAR
c> SCALAR
Re: Pointer syntax question [ In reply to ]
Drop that one - it suddenly started functioning. Might have been an
old copy getting executed in the path... But I may be back because
the "real" program is still not functioning as expected. I've just
not caught the right part of it. (Oh for the days of Bliss-11 pointers :-)
Re: Pointer syntax question [ In reply to ]
On Wed, 6 Sep 1995, David Avraamides wrote:

> Try it again with the noted correction and you'll be ok.
> (One of my old CS professors told be the best debugging
> tool is a second pair of eyes...)
>
> -Dave

Too true, too true... Explains why the example started working suddenly.
I did a global replace to make sure the lengths didn't change. I never
noticed the extra CAP N... Now, will that fix problems in the real program?
Stay tuned for further adventures in Perl Hyperspace... :-)
Re: Pointer syntax question [ In reply to ]
>>>>> Dale Amon writes:

Dale> Oopps, I lifted the wrong part of the test program - I was trying it
Dale> with two different parts of the same structure. Here is the entire
Dale> thing and the entire output:

Dale> #!/usr/local/bin/perl -w

Dale> $db = {};
Dale> $db->{'HostnameIndex'} = {};
^-----> should be 'N' !!!

Dale> print "db> ";
Dale> print ref ($db);
Dale> print "\na> ";
Dale> print ref ($db->{'HostNameIndex'});
Dale> print "\nb> ";
Dale> print ref (\$db->{'HostNameIndex'});
Dale> print "\nc> ";
Dale> print ref (\($db->{'HostNameIndex'}));
Dale> print "\n";

Try it again with the noted correction and you'll be ok.
(One of my old CS professors told be the best debugging
tool is a second pair of eyes...)

-Dave