in reply to What's the idiom for finding and removing the found @ARRAY element?

I thought that in recent versions of perl you could do delete() on array elements, just like you can on hash keys?
--
($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;
  • Comment on Re: What's the idiom for finding and removing the found @ARRAY element?
  • Download Code

Replies are listed 'Best First'.
Re: Re: What's the idiom for finding and removing the found @ARRAY element?
by BrowserUk (Patriarch) on Nov 06, 2002 at 05:48 UTC

    You can. Unfortunately, all it seems to do is set the element to undef unless it also happens to be the last (highest) element in the array, in which case it does also remove it and reduces the overall size of the array.

    If it is any element other than the last, the array stays the same size, and the rest of the elements retain their previous indices.


    Nah! You're thinking of Simon Templar, originally played (on UKTV) by Roger Moore and later by Ian Ogilvy
Re: Re: What's the idiom for finding and removing the found @ARRAY element?
by Enlil (Parson) on Nov 06, 2002 at 05:50 UTC
    You can, delete $array[$index] as long as you note that all delete does is set that array position to an uninitialized state, but leaves the other elements in the array in their current positions (same amount of elements in the array but now one is unintialized). Unless, it is the last element that you deleted.