Hello y'all:
What is the accepted (and safest!) way of comparing pointers (references)
in Perl?
I.e., I have a linked list and need to follow a part of it (pointed to by
a starting and an ending pointer) and to insert and delete elements (if
the deleted element happens to be the last of a section, the ending pointer
has to be updated!).
Also, what is an acceptable test for a "NIL" (= "NULL") pointer?
I'm currently using this (my pointers are all pointing to anonymous ARRAYs):
$NULL = 0;
# could be just any value; ref(\$NULL) needs to be != 'ARRAY' (is 'SCALAR')
$this = \$NULL;
$that = [ ];
if (ref($this) =~ /ARRAY/)
{ print "It's a valid pointer\n"; }
else
{ print "It's a NULL pointer\n"; }
if (ref($that) =~ /ARRAY/)
{ print "It's a valid pointer\n"; }
else
{ print "It's a NULL pointer\n"; }
This prints
It's a NULL pointer
It's a valid pointer
Any pointers ;-) welcome!
Thanks!
Yours,
--
Steffen Beyer
mailto:sb@sdm.de |s |d &|m | software design & management GmbH&Co.KG
phone: +49 89 63812-244 | | | | Thomas-Dehler-Str. 27
fax: +49 89 63812-150 | | | | 81737 Munich, Germany.
What is the accepted (and safest!) way of comparing pointers (references)
in Perl?
I.e., I have a linked list and need to follow a part of it (pointed to by
a starting and an ending pointer) and to insert and delete elements (if
the deleted element happens to be the last of a section, the ending pointer
has to be updated!).
Also, what is an acceptable test for a "NIL" (= "NULL") pointer?
I'm currently using this (my pointers are all pointing to anonymous ARRAYs):
$NULL = 0;
# could be just any value; ref(\$NULL) needs to be != 'ARRAY' (is 'SCALAR')
$this = \$NULL;
$that = [ ];
if (ref($this) =~ /ARRAY/)
{ print "It's a valid pointer\n"; }
else
{ print "It's a NULL pointer\n"; }
if (ref($that) =~ /ARRAY/)
{ print "It's a valid pointer\n"; }
else
{ print "It's a NULL pointer\n"; }
This prints
It's a NULL pointer
It's a valid pointer
Any pointers ;-) welcome!
Thanks!
Yours,
--
Steffen Beyer
mailto:sb@sdm.de |s |d &|m | software design & management GmbH&Co.KG
phone: +49 89 63812-244 | | | | Thomas-Dehler-Str. 27
fax: +49 89 63812-150 | | | | 81737 Munich, Germany.