perl - Deleting items from an array and collapsing it after -
using perl, have array of ip addresses i'm storing in array. there many operations done on elements in array , 1 of them delete ip address. know can use delete
function, leaves empty spot in array. there function/way delete item array , collapse/shift elements there no empty spots.
for example, there 10 elements in array. delete 3rd element. there 9 elements , 4th element becomes 3rd, 5th becomes 4th, etc.
thank help!
lets have 10-element array:
my @arr = (0..9);
then want remove element 3, or offset 2:
my $third_element = splice @arr, 2, 1;
@arr
0, 1, 3, 4, 5, 6, 7, 8, 9.
Comments
Post a Comment