Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Deleteing array elements

by Corion (Patriarch)
on Jul 23, 2009 at 07:08 UTC ( [id://782583]=note: print w/replies, xml ) Need Help??


in reply to Deleteing array elements

@a = ['a','b','c','d'];

That's likely not "an array" in the sense you want. That's just an array with a single element that is a reference to another array with four elements. More likely, you want an array of four elements for a start:

@a = ('a','b','c','d');

Then you want to read splice and then use it.

Replies are listed 'Best First'.
Re^2: Deleteing array elements
by ciderpunx (Vicar) on Jul 23, 2009 at 07:18 UTC
    Once you've got your array set up as described by Corion, use splice
    my @a=('a','b','c','d'); splice @a, 2, 1; print join ",", @a;
    --
    Linux, perl, punk rock, cider: charlieharvey.org.uk.
      I prefer to write splice @a, 2, 1, (); it doesn't do anything different, but it makes things clear as well as making things parallel with substr (substr and splice act differently with three arguments, but they act the same with four). Am I the only one?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-19 15:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found