Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Deleteing array elements

by FunkyMonk (Chancellor)
on Jul 23, 2009 at 07:16 UTC ( [id://782584]=note: print w/replies, xml ) Need Help??


in reply to Deleteing array elements

You probably haven't got the data structure you think you have. What I think you mean is:
my @a = ('a', 'b', 'c', 'd'); #or my @a = qw( a b c d );

To delete the array element containing 'c', see grep:

@a = grep { $_ ne 'c' } @a;

Update Further to Corion's (and others) advice

  • If you know the index of the element you want to delete, use splice
  • If you know the contents of the element you want to delete, use grep

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-25 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found