[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: exists $foo[7] and delete $foo[7]
On Thu, 13 Jan 2000 17:26:13 GMT, Pete Jordan wrote:
>Gurusamy Sarathy wrote:
>> scalar(@array) and $#array are still related in the same way as before,
>> but it _would_ be semantically cleaner for the former returning just the
>> number of initialized values. But we really can't do that without
>> breaking compatibility.
>
>How so? There's nothing to break compatibility with: The old (current)
>definition of C<scalar @foo> would be "the number of elements that exist
>in the array (excluding putative non-existent elements that can't yet,
>errm, exist)"...
>
>As long as you carry on counting /undefined/ values, nothing can break.
>Anyone who did C<@foo=(1, 2, 3); delete $foo[1]; $foo[scalar @foo]=4;>
>would get what they deserved ;)
If we made scalar(@foo) only count the initialized valuse (a.k.a values
that exist), the following code will break:
$foo[3] = 4; # @foo[0,1,2] are uninitialized, even in perl 5.005
if (@foo > 2) {
...
}
I don't think we can do it. Besides, it possibly reads better to extend
values() to do that instead.
Sarathy
gsar@ActiveState.com
- Follow-Ups from:
-
pete@horus.cix.co.uk (Pete Jordan)
- References to:
-
Pete Jordan <pjordan1@email.mot.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]