in reply to Re^2: Splicing Arrays on pre-defined indices
in thread Splicing Arrays on pre-defined indices

Thx for reply, let me make my question rather more simple
# Assume below line is read from a file my @array = qw/i will skip some words here using splice/; print "Array before deletion \n"; print join("-->",@array),"\n"; print "Enter the Indices which you like to skip\n"; chomp($indices=<STDIN>); # i entered 2,4,5 my @indices = split(/\,/,$indices); foreach (@indices){ splice (@array,$_,1); # remove element } print "Updated array is as below \n"; print join("==>",@array),"\n"; # if there is any easy way of doing above in short , i can integrate i +n my existing code

Replies are listed 'Best First'.
Re^4: Splicing Arrays on pre-defined indices
by BrowserUk (Patriarch) on Jun 27, 2008 at 18:15 UTC

    All you need is an array slice:

    ## Assume @array contains fields (from wherever) ## Assume @indices contains field numbers to keep (from wherever) @array = @array[ @indices ]; ## Now, @array only contains the fields you want to keep.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.