Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Removing elemets from an array

by linuxer (Deacon)
on Dec 28, 2012 at 08:18 UTC ( #1010671=note: print w/ replies, xml ) Need Help??


in reply to Removing elemets from an array

The hint to perlfaq4 is excellent.

Use a hash and grep() and you are fine. No need for delete() or splice() here.

#! /usr/bin/perl use strict; use warnings; my @arcb = ( 450, 625, 720, 645 ); my @arca = ( 625, 645 ); ### see perlfaq4 - How can I remove duplicate elements from a list or +array? my %unwanted; ### or %seen as in the faq4 $unwanted{$_}++ for @arca; @arcb = grep { !$unwanted{$_} } @arcb; print "@arcb\n"; + __END__ +

Updates


Comment on Re: Removing elemets from an array
Download Code
Replies are listed 'Best First'.
Re^2: Removing elemets from an array
by lovelyMonk (Initiate) on Dec 28, 2012 at 10:05 UTC
    Worked perferctly for me :) Thankyou

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2015-07-29 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls