Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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__ +

Updates

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 about the Monastery: (7)
As of 2016-07-01 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (410 votes). Check out past polls.