xeoron has asked for the wisdom of the Perl Monks concerning the following question:

How would I go about deleting the a row of a AoA? This is for a k-means clustering program that I am writing for my DataMining class.

Replies are listed 'Best First'.
Re: AoA row deleting
by davido (Cardinal) on Mar 19, 2004 at 06:19 UTC
    Can I assume that the top-level array is what you consider a row, and the array-ref it holds points to an array that you consider to be the columns?

    If that's the case, here's an example of deleting a "row".

    use strict; use warnings; use Data::Dumper; my @aoa = ( [1, 2, 3], [4, 5, 6], [7, 8, 9] ); splice @aoa, 1, 1; print Dumper \@aoa;

    You'll notice that the output of the above snippet indicates that the "row" containing "4, 5, 6" has been deleted. Be sure to see perldoc -f splice for details.


    Dave

Re: AoA row deleting
by kvale (Monsignor) on Mar 19, 2004 at 06:20 UTC
    To delete an element of an array, use the splice function:
    my $AoA_ref = [ [1,2,3], [4,5,6], [7,8,9] ]; my $row = 2; my $deleted_row_ref = splice @$AoA_ref, $row, 1;

    -Mark