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
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 drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2014-09-18 09:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (109 votes), past polls