Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multidimential Array Size

Status
Not open for further replies.

mcbrune

Programmer
Jul 23, 2001
7
US
I need to find either the size of a multidimential array, or the last item in the array. The array is from a query from PostgreSQL database, and I need to do a 'next' when either the size of the last item is reached.

Thanks for any help!

Corey
 
It depends on which dimention you want. You should be able to pick it out of one of these.
Code:
my @multi = (   [ '(0,0)', '(0,1)', '(0,2)' ],
                [ '(1,0)', '(1,1)', '(1,2)' ],
                [ '(2,0)', '(2,1)', '(2,2)' ],
                [ '(3,0)', '(3,1)', '(3,2)' ],
                [ '(4,0)', '(4,1)', '(4,2)' ],
                [ '(5,0)', '(5,1)', '(5,2)' ],
        );
my $num_rows = @multi;
my $last_row_index = $#multi;

my $row1_num_elems = @{ $multi[1] };
my $row3_last_index = $#{ $multi[3] };

print "Number of rows is $num_rows\n";
print "Last index is $last_row_index with value @{$multi[$last_row_index]}\n";
print "Number of columns in row 1 is $row1_num_elems\n";
print "Last index of row 3 is $row3_last_index with value $multi[3][$row3_last_index]\n";
which outputs
Code:
Number of rows is 6
Last index is 5 with value [ (5,0) (5,1) (5,2) ]
Number of columns in row 1 is 3
Last index of row 3 is 2 with value (3,2)
jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top