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

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?

  • Comment on Re^3: using function delete with arrays

Replies are listed 'Best First'.
Re^4: using function delete with arrays
by locked_user rumos-er (Novice) on Jul 18, 2007 at 06:24 UTC
    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.