use strict;
my @array=qw(a b c d e f g h);
splice(@array,1,1);
print "new list = @array";
will return:
a c d e f g h
In your mesasge you say "I know I want to remove the second value, $array[2].
How should I do this?.." but second value has [1] and not [2] :-)
You can remove multiple elements.. use splice(@array,2,3) to remove the 3rd 4th
and 5th elements..(3 elements from the [2]), and so on.
You can also assign the removed values.. @removed = splice(@array,2,3); it will
store in @removed values "c" "d" and "e".
You can replace values..
my @new_arr = (1,2,3,4,5); splice(@array,2,3,@new_arr); print @arr;
will return: a b 1 2 3 4 5 f g h
Hope this helps
Etienne
wh wrote:
> Hi,
>
> This works but it can't be this easy, so tell this true beginner what's
> wrong with it! I checked it with print "@array\n"; and got an error message
> about an "uninitialized value in join or string" I don't know how to deal
> with.
>
> @array = (1, 2, 3, 4, 5);
> delete $array[2];
>
> Wendy.
>
> "Andrew Mason" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Say I have an array @array = ( 1, 2, 3, 4, 5)
>
> I know I want to remove the second value, $array[2]. How should I do
> this?
>
> Is it possible to issue a command that just does this for me or do I
> have to loop through setting $array[n]=$array[n+1] for n>which ever
> value I wish to remove? (I hope that makes sense).
>
> The second solution whilst effectively removing the unwanted element
> would mean that the end of my array was filled with duplicates or
> rubbish, so isn't really a solution unless I can then tidy it up
> somehow.
>
> TIA
>
> Andrew
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
S/MIME Cryptographic Signature