Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Splicing Arrays on pre-defined indices

by harishnuti (Beadle)
on Jun 27, 2008 at 18:01 UTC ( [id://694408]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://694408]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-16 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found