in reply to Re: delete array element from array ref
in thread delete array element from array ref

Another way to avoid holes would be to filter out the holes with something like

@{$listref} = grep { defined } @{$listref};

after performing the deletion. (Of course that assumes that undef isn't a valid value in the list.)

Replies are listed 'Best First'.
Re^3: delete array element from array ref
by GrandFather (Saint) on Aug 22, 2008 at 07:42 UTC

    Better would be:

    @{$listref} = grep {exists} @{$listref};

    Update: this is of course complete bolix as pointed out by tinita++.


    Perl reduces RSI - it saves typing
      @{$listref} = grep {exists} @{$listref};
      maybe you meant:
      @{$listref} = map { exists $listref->[$_] ? $listref->[$_] : () } 0 .. $#{$listref} ;
      ?

      update: typo