in reply to Re: using function delete with arrays
in thread using function delete with arrays

1. I know about slice. Thnx.
2. So where is a bug or logical humor of function delete ?
2.1. When all elements of array are 'deleted' then array is realy clear.
2.2. Also if I make delete of last(!) element(-s) of array - number of array items will changes (I calculate it as result of scalar function not as $#).
As I understand - scalar or delete works wrong. Exactly what of them - is my main question :)

Replies are listed 'Best First'.
Re^3: using function delete with arrays
by Anonymous Monk on Jul 17, 2007 at 17:14 UTC

    2.1, 2.2: The first paragraph of "perldoc -f delete" contains:

    In the case of an array, if the array elements happen to be at the end, the size of the array will shrink to the highest element that tests true for exists() (or 0 if no such element exists).

    Does this reasonably answer your question?

      I know this, but:
      1. if test for 'exists' returns false for deleted elements - then why scalar returns number of all elements ? (with deleted).
      2. if delete realy delete last elements - why it doesn't delete middle elements ?
      this is a questions about language realisation, not about how this function work.. I trying to understand for which purposes I can use this function.
        why it doesn't delete middle elements ?

        That is a really good question. My best guess is that it would be useful if an array was tie'ed to a database.
        Personally I do not find delete used on an array to be particularly useful. My suggestion is that you use splice instead, which has been around much longer.
        Deleting elements from within an array is not really something that needs to be done very often, the (non-tie) cases I can think of would all be better done using a hash.