Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Removing elemets from an array

by linuxer (Curate)
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__ +


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?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2016-10-22 06:16 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (292 votes). Check out past polls.