develooper Front page | perl.perl5.porters | Postings from July 2011

[perl #94972] The 'exists' function needs expansion, not depreciation

Thread Previous | Thread Next
Brendan Byrd
July 17, 2011 14:14
[perl #94972] The 'exists' function needs expansion, not depreciation
Message ID:
# New Ticket Created by  Brendan Byrd 
# Please include the string:  [perl #94972]
# in the subject line of all future correspondence about this issue. 
# <URL: >

Traditionally, Perl has maintained their version of the NULL value = undef.
This aspect of variables needs to be expanded on, but potentially new
changes may take a step backwards:

exists may also be called on array elements, but its behavior is much less
obvious and is strongly tied to the use of
delete<>on arrays.
* Be aware that calling exists on array values is deprecated and likely to
be removed in a future version of Perl.*

There's a need for variables to exist in a state of "initialized, but
undefined".  All variables, not just hashes.  And these states need to be
detectable as "initialized, but undefined".  As in "my container's value is
undefined, but my container still exists."  Zero-like values like '' or 0
are different than NULL or undef.

Instead of removing functionality from the 'exists' function, it should be
expanded to work on scalars, arrays, hashes, code containers, references,
even globs and filehandles.  If the behavior of undef doesn't work in all
cases, then that should be fixed as well:

$aaa = undef;  # initialized, but undefined
undef $bbb;  # removes the container, so the variable is now uninitialized
$ccc[4] = undef;  # initialized, but undefined (even if it's the last one in
the array)
$ddd{'key'} = undef;  # initialized, but undefined
$ddd{undef} = undef;  # still valid
$ccc[undef] = undef;  # illegal (undef isn't a number)
undef $ccc[4];  # either illegal or works like splice
undef $ddd{'key'};  # either illegal or works like delete

exists $aaa && !defined $aaa;  # true for both
exists $ccc[4] && !defined $ccc[4];  # true for both
exists $ddd{'key'} && !defined $ddd{'key'};  # true for both

In other words, the left side and the right side of undef should work
differently.  Making something undefined and undefining something are two
different things.

Brendan Byrd/SineSwiper <>
Computer tech, PERL wizard, and all-around Internet guru

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About